Game over screen
- Game Development course
- Advanced
- Lesson 53/71
- 4 min
Learn to build the game over screen with UI.
Game Over Panel
When player lives exhaust or time expires, game over is triggered. The Canvas Game Over panel, inactive by default, is shown via gameOverPanel.SetActive(true).
public GameObject gameOverPanel;
public void GameOver() {
gameOverPanel.SetActive(true);
Time.timeScale = 0f; // Freeze physics and time
}Setting Time.timeScale = 0f; freezes gameplay motion and updates across the scene.
Restarting and SceneManager
When the 'Restart' button on the Game Over screen is clicked, time scale is restored with Time.timeScale = 1f; and the active scene reloads via SceneManager.LoadScene.
using UnityEngine.SceneManagement;
public void RestartGame() {
Time.timeScale = 1f;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}This resets all actors and game entities back to their initial scene state.
Practice Game over panel status
Define a Start method. Inside, declare string durum = "Oyun sonu paneli aktif"; and print it to the console with Debug.Log(durum);.
Starter code
using UnityEngine;
public class GameOverTester : MonoBehaviour
{
// Start icinde durum tanimla ve yazdir
}Sample solution
using UnityEngine;
public class GameOverTester : MonoBehaviour
{
void Start()
{
string durum = "Oyun sonu paneli aktif";
Debug.Log(durum);
}
}Expected output
Oyun sonu paneli aktif
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which Unity command freezes physics and scene movement entirely when the game ends?
- Screen.fullScreen = false;
- AudioListener.pause = false;
- QualitySettings.SetQualityLevel(0);
- Time.timeScale = 0f; Correct answer
Explanation: Assigning Time.timeScale = 0f; scales game time to zero, halting deltaTime-based updates and physics simulations.
2 Activate panel
gameOverPanel.____(true);
gameOverPanel.SetActive(true);
Explanation: The 'SetActive(true)' method is called to make a GameObject active and visible in the scene.
3 Game over concepts
| Term | Meaning |
|---|---|
gameOverPanel |
UI panel displayed upon game over |
Time.timeScale = 0f |
Pauses game time and motion |
Restart |
Reloads scene and resets the game |
SceneManager.LoadScene |
Loads designated scene into memory |