Challenge - 5 Problems
Game State UI Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What does this Unity UI code display when the player loses?
Consider this Unity C# script attached to a UI Text element. What text will appear when the player's health reaches zero?
Unity
using UnityEngine; using UnityEngine.UI; public class GameStateUI : MonoBehaviour { public int playerHealth = 10; public Text statusText; void Update() { if (playerHealth <= 0) { statusText.text = "Game Over"; } else { statusText.text = "Health: " + playerHealth; } } }
Attempts:
2 left
💡 Hint
Look at the condition that changes the statusText.text in Update().
✗ Incorrect
The code updates the UI text every frame. When playerHealth is 0 or less, it sets the text to "Game Over". Otherwise, it shows the current health.
🧠 Conceptual
intermediate1:30remaining
Why should UI reflect game state changes?
Why is it important for the UI to update and show the current game state to the player?
Attempts:
2 left
💡 Hint
Think about how players use the UI during a game.
✗ Incorrect
The UI shows important information like health, score, or status. This helps players understand what is happening and decide what to do next.
🔧 Debug
advanced2:30remaining
Why does this UI not update when playerHealth changes?
This Unity script is supposed to update the UI text when playerHealth changes, but it does not. What is the problem?
Unity
using UnityEngine; using UnityEngine.UI; public class GameStateUI : MonoBehaviour { public int playerHealth = 10; public Text statusText; void Start() { if (playerHealth <= 0) { statusText.text = "Game Over"; } else { statusText.text = "Health: " + playerHealth; } } }
Attempts:
2 left
💡 Hint
Check when the UI text is updated in the code.
✗ Incorrect
The UI text is set only once in Start(). If playerHealth changes later, the UI does not update because Update() or another method is not changing the text.
📝 Syntax
advanced1:30remaining
What error does this Unity UI code produce?
Look at this code snippet. What error will it cause when compiled?
Unity
using UnityEngine; using UnityEngine.UI; public class GameStateUI : MonoBehaviour { public int playerHealth = 10; public Text statusText; void Update() { if (playerHealth <= 0) { statusText.text = "Game Over"; } } }
Attempts:
2 left
💡 Hint
Check the declaration line for statusText.
✗ Incorrect
The line 'public Text statusText' is missing a semicolon at the end, causing a compile error.
🚀 Application
expert3:00remaining
How many UI elements are needed to fully communicate player status?
A game wants to show the player's health, score, and current weapon on screen. How many separate UI elements should be used to clearly communicate this game state?
Attempts:
2 left
💡 Hint
Think about clarity and ease of reading for the player.
✗ Incorrect
Using separate UI elements for each piece of information helps players quickly understand their status without confusion.