Skip to main content
Unity 3D Basics – Complete Beginner to Advanced Guide
CHAPTER 12 Beginner

Scene Management and Game Flow

Updated: May 16, 2026
25 min read

# CHAPTER 12

Scene Management and Game Flow

1. Introduction

A video game is rarely just one continuous 3D space. You start at a Main Menu. You click "Play" and load Level 1. If you die, a "Game Over" screen appears, and you are teleported back to the beginning. This transition of states is known as Game Flow. In Unity, individual levels or menus are saved as Scenes (.unity files). In this chapter, we will master Scene Management. We will learn how to transition between levels using C#, configure the Build Settings, build a functional Main Menu, and implement a robust Pause system.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Understand what a Unity Scene is and how to manage multiple scenes.
  • Add scenes to the Build Settings index.
  • Use SceneManager.LoadScene() to transition between levels.
  • Create a functional Main Menu with "Play" and "Quit" buttons.
  • Implement a Pause system using Time.timeScale.

3. Scenes and Build Settings

A Scene contains all the GameObjects, lights, and UI for a specific part of your game.
  • You might have a MainMenu scene, a Level01 scene, and a Level02 scene.
  • Before Unity can switch between them, it needs a master list.
  1. 1. Go to File -> Build Settings.
  1. 2. Open your Project window and drag your scene files into the Scenes In Build box.
  1. 3. The order matters! The scene at index 0 (the top of the list) is the one that loads automatically when the player launches the actual .exe game.

4. Loading Scenes with C#

To load a scene, your script needs the specific namespace: using UnityEngine.SceneManagement;.
csharp
1234567891011121314151617181920
using UnityEngine;
using UnityEngine.SceneManagement; // REQUIRED!

public class LevelManager : MonoBehaviour
{
    public void LoadNextLevel()
    {
        // Load the scene by its exact string name
        SceneManager.LoadScene("Level_02");
        
        // OR load by its index number in the Build Settings
        // SceneManager.LoadScene(1);
    }

    public void RestartCurrentLevel()
    {
        // A neat trick to reload whatever scene is currently active!
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }
}

5. Building a Main Menu

  1. 1. Create a new Scene (Ctrl+N) and save it as MainMenu.
  1. 2. Add a UI Canvas and two Buttons: "Start Game" and "Quit".
  1. 3. Create a MainMenuManager script.
  1. 4. Hook the "Start Game" button to a function that calls SceneManager.LoadScene("Level_01").
  1. 5. Hook the "Quit" button to a function that calls Application.Quit(). *(Note: Quit only works in the built .exe game, it does nothing when playing inside the Unity Editor).*

6. Pausing the Game (TimeScale)

How do you freeze all enemies, physics, and animations instantly to show a Pause Menu? Unity uses a global multiplier called Time.timeScale.
  • Time.timeScale = 1f; (Normal speed).
  • Time.timeScale = 0.5f; (Matrix-style slow motion).
  • Time.timeScale = 0f; (Completely frozen).
csharp
12345678910111213141516171819202122232425
public GameObject pauseMenuUI; // The Canvas panel containing the menu
private bool isPaused = false;

void Update()
{
    if (Input.GetKeyDown(KeyCode.Escape))
    {
        if (isPaused) ResumeGame();
        else PauseGame();
    }
}

public void PauseGame()
{
    pauseMenuUI.SetActive(true); // Show the menu graphics
    Time.timeScale = 0f;         // Freeze the game physics/movement
    isPaused = true;
}

public void ResumeGame()
{
    pauseMenuUI.SetActive(false); // Hide the menu
    Time.timeScale = 1f;          // Unfreeze the game!
    isPaused = false;
}

7. Visual Learning: Game Flow Architecture

txt
123456789101112131415
               [ Application Launched ]
                         |
           (Loads Build Index 0 Automatically)
                         v
                  [ Main Menu Scene ]
                         |
       (Player clicks "Start" -> LoadScene(1))
                         v
                  [ Level 01 Scene ]
                    /            \
       (Player hits Escape)    (Player reaches door)
             /                        \
    [ Pause Menu UI ]          (LoadScene(2))
    (TimeScale = 0)                   v
                              [ Level 02 Scene ]

8. Best Practices

  • DontDestroyOnLoad: Normally, when you load a new scene, Unity deletes absolutely everything from the old scene. If you have an AudioSource playing background music, the music will awkwardly restart. You can attach a simple script to your MusicManager containing DontDestroyOnLoad(gameObject);. This magical function tells Unity to carry the object over into the new scene without destroying it, ensuring uninterrupted music!

9. Common Mistakes

  • Restarting a Paused Game: A player dies while the game is paused (TimeScale = 0), and they click "Restart Level". The level reloads, but nothing moves! The game is completely frozen! TimeScale is a global setting that persists across scenes. If you set it to 0, you MUST remember to set Time.timeScale = 1f; inside the Start() method of your LevelManager so the game always unfreezes on a fresh load.

10. Mini Project: The Portal

Objective: Create a physical trigger that loads the next level.
  1. 1. Ensure you have Level01 and Level02 added to your Build Settings.
  1. 2. In Level_01, create a glowing Cylinder and check Is Trigger on its collider.
  1. 3. Attach this script to the Cylinder:
csharp
12345678910111213141516
using UnityEngine;
using UnityEngine.SceneManagement;

public class LevelPortal : MonoBehaviour
{
    public string nextLevelName; // Type "Level_02" in the Inspector

    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            Debug.Log("Teleporting to next level!");
            SceneManager.LoadScene(nextLevelName);
        }
    }
}
  1. 4. Walk your player into the cylinder and watch the scene seamlessly transition!

11. Practice Exercises

  1. 1. What menu window must you open to add your scenes into a master index list before they can be loaded via script?
  1. 2. What C# variable controls the global speed of physics, animations, and Time.deltaTime, allowing you to pause the game?

12. MCQs with Answers

Question 1

To use the SceneManager class in your C# script, which line of code MUST be present at the very top of the file?

Question 2

When the player clicks the "Quit" button on the Main Menu, the script executes Application.Quit(). Why does nothing happen when you test this in the Unity Editor?

13. Interview Questions

  • Q: Walk me through the exact pipeline required to transition from a MainMenu scene to a Level_01 scene when a UI button is clicked.
  • Q: Explain how Time.timeScale works in Unity. Provide an example of a severe game-breaking bug that can occur if timeScale is not managed properly across scene transitions.
  • Q: What is the purpose of the DontDestroyOnLoad method? Provide a scenario where its usage is critical for a smooth player experience.

14. FAQs

Q: My game has a giant open world. Do I have to load it all at once? A: No! Advanced games use "Additive Scene Loading". You can load the "Forest" scene on top of the "City" scene seamlessly in the background without a loading screen while the player is walking!

15. Summary

In Chapter 12, we connected our fragmented scenes into a cohesive game flow. We learned how to register our scenes in the Build Settings index. We utilized SceneManager.LoadScene() to trigger level transitions physically (via Portals) and via UI (Main Menus). We programmed a robust Pause architecture by manipulating Time.timeScale to freeze the simulation, and learned the critical rule of resetting that time scale on a level reload.

16. Next Chapter Recommendation

Our game has flow, but the player has no motivation. Let's give them something to collect. Proceed to Chapter 13: Collectibles, Inventory, and Scoring Systems.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·