Menu
CoddyTech

Recap: Level Select

Part of the Building Real Games section of Coddy's Unity journey. Lesson 21 of 60.

This recap puts the chapter together: a manager that survives scene loads with DontDestroyOnLoad, and buttons that load scenes by name or number. Finishing a level opens the next one on the menu.

challenge icon

Challenge

Easy

Build a level select that opens levels as they are finished.

  1. Progress.Awake(): destroy a newcomer and return, else set Instance and call DontDestroyOnLoad(gameObject).
  2. LevelDone(int level): unlocked = Mathf.Max(unlocked, level + 1);, then load Menu.
  3. LevelSelect.Start(): button i loads level i + 1 (copy it first) and is interactable only up to Progress.Instance.unlocked.

Press Play and finish Level 1: the Level 2 button opens. Then Check.

Try it yourself

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class LevelSelect : MonoBehaviour
{
    public Button[] levelButtons;

    void Start()
    {
        // each button opens its level; locked levels cannot be clicked
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Building Real Games

Practice on your own: Unity playground