0
0
Unityframework~10 mins

Why UI communicates game state in Unity - Test Your Understanding

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

Complete the code to update the UI text with the player's score.

Unity
scoreText.text = "Score: " + [1].ToString();
Drag options to blanks, or click blank then click option'
AgameState
BscoreText
CUpdateScore
DplayerScore
Attempts:
3 left
💡 Hint
Common Mistakes
Using the UI text object itself instead of the score variable.
Using a method name instead of a variable.
2fill in blank
medium

Complete the code to show the game over panel when the game ends.

Unity
if (gameState == GameState.GameOver) {
    [1].SetActive(true);
}
Drag options to blanks, or click blank then click option'
AgameOverPanel
BscoreText
Cplayer
DstartButton
Attempts:
3 left
💡 Hint
Common Mistakes
Activating the wrong UI element like the score text or player object.
Trying to activate a button instead of the panel.
3fill in blank
hard

Fix the error in the code that updates the health bar UI.

Unity
healthBar.fillAmount = [1] / maxHealth;
Drag options to blanks, or click blank then click option'
AplayerHealth
BhealthBar
CcurrentHealth
DmaxHealth
Attempts:
3 left
💡 Hint
Common Mistakes
Using maxHealth as numerator, which always results in 1.
Using the UI element variable instead of health value.
4fill in blank
hard

Fill both blanks to create a dictionary that maps game states to UI panels.

Unity
Dictionary<GameState, GameObject> uiPanels = new Dictionary<GameState, GameObject> {
    { GameState.Playing, [1] },
    { GameState.Paused, [2] }
};
Drag options to blanks, or click blank then click option'
AplayingPanel
BgameOverPanel
CpausedPanel
DstartPanel
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up panels for different game states.
Using the game over panel for Playing or Paused states.
5fill in blank
hard

Fill all three blanks to update the UI only when the game state changes.

Unity
if (currentState != [1]) {
    currentState = [2];
    UpdateUI([3]);
}
Drag options to blanks, or click blank then click option'
ApreviousState
BnewState
CcurrentState
DgameState
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable for comparison or assignment.
Passing the wrong state to the UpdateUI function.