0
0
Unityframework~10 mins

State synchronization in Unity - 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 synchronized variable in Unity using Mirror.

Unity
[SyncVar] private [1] playerHealth = 100;
Drag options to blanks, or click blank then click option'
Aint
Bstring
Cbool
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string or bool type for health causes errors or unexpected behavior.
2fill in blank
medium

Complete the code to send a command from the client to the server in Unity Mirror.

Unity
[Command] public void CmdChangeColor(Color [1]) { playerColor = color; }
Drag options to blanks, or click blank then click option'
Achange
BnewColor
Ccolor
Dcol
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name that doesn't match the variable inside the method causes errors.
3fill in blank
hard

Fix the error in the code to properly synchronize a player's score using SyncVar hook.

Unity
[SyncVar(hook = nameof(OnScoreChanged))] private int [1];

void OnScoreChanged(int oldScore, int newScore) {
    scoreText.text = newScore.ToString();
}
Drag options to blanks, or click blank then click option'
AscoreValue
BplayerScore
Cpoints
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that doesn't match the hook method causes synchronization issues.
4fill in blank
hard

Fill both blanks to create a filtered dictionary for high scores (above 10).

Unity
private Dictionary<string, int> playerScores = new Dictionary<string, int>();

var highScores = playerScores.Where(kvp => kvp.Value > 10).ToDictionary(kvp => kvp.[1], kvp => kvp.[2]);
Drag options to blanks, or click blank then click option'
AKey
BValue
Cvar
DplayerScores
Attempts:
3 left
💡 Hint
Common Mistakes
Using the whole variable instead of .Key or .Value causes errors.
5fill in blank
hard

Fill all three blanks to correctly update and synchronize a player's position on the server.

Unity
[Command]
public void CmdUpdatePosition(Vector3 [1]) {
    transform.[2] = [3];
}
Drag options to blanks, or click blank then click option'
AnewPosition
Bposition
DlocalPosition
Attempts:
3 left
💡 Hint
Common Mistakes
Using localPosition instead of position changes local space, not world space.