0
0
Unityframework~10 mins

Unity Netcode overview - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a NetworkVariable of type int.

Unity
public NetworkVariable<int> playerScore = new NetworkVariable<[1]>();
Drag options to blanks, or click blank then click option'
Aint
Bfloat
Cstring
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using a type that does not match the intended data, like float or string.
2fill in blank
medium

Complete the code to check if the current instance is the server.

Unity
if (NetworkManager.Singleton.[1]) {
    // Server-only logic here
}
Drag options to blanks, or click blank then click option'
AIsConnected
BIsHost
CIsClient
DIsServer
Attempts:
3 left
💡 Hint
Common Mistakes
Using IsClient which checks for client role instead.
3fill in blank
hard

Fix the error in the method to send a server RPC.

Unity
[ServerRpc]
public void SendMessageToServer(string message) {
    [1]
}
Drag options to blanks, or click blank then click option'
ADebug.Log(message
BDebug.Log(message);
CDebug.Log(message))
DDebug.Log(message)
Attempts:
3 left
💡 Hint
Common Mistakes
Missing semicolon at the end of the statement.
4fill in blank
hard

Fill both blanks to create a NetworkObject and spawn it on the server.

Unity
var obj = Instantiate([1]);
obj.[2]();
Drag options to blanks, or click blank then click option'
Aprefab
BDestroy
CSpawn
DGameObject
Attempts:
3 left
💡 Hint
Common Mistakes
Calling Destroy instead of Spawn.
Using GameObject instead of the prefab variable.
5fill in blank
hard

Fill all three blanks to create a NetworkVariable, set its value, and read it.

Unity
NetworkVariable<int> score = new NetworkVariable<int>();
score.[1] = 10;
int currentScore = score.[2];
Debug.Log([3]);
Drag options to blanks, or click blank then click option'
AValue
CcurrentScore
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to log the NetworkVariable object directly instead of the stored value.