Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a type that does not match the intended data, like float or string.
✗ Incorrect
The NetworkVariable is declared with the type int to hold integer values like player scores.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
IsClient which checks for client role instead.✗ Incorrect
IsServer is true when the current instance is running as the server.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Missing semicolon at the end of the statement.
✗ Incorrect
The statement must end with a semicolon to be syntactically correct in C#.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling Destroy instead of Spawn.
Using GameObject instead of the prefab variable.
✗ Incorrect
Instantiate the prefab and call Spawn() to make it a networked object on the server.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to log the NetworkVariable object directly instead of the stored value.
✗ Incorrect
Use the Value property to set and get the NetworkVariable's value. Then log the currentScore variable.