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
EasyBuild a level select that opens levels as they are finished.
Progress.Awake(): destroy a newcomer and return, else setInstanceand callDontDestroyOnLoad(gameObject).LevelDone(int level):unlocked = Mathf.Max(unlocked, level + 1);, then loadMenu.LevelSelect.Start(): buttoniloads leveli + 1(copy it first) and isinteractableonly up toProgress.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
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Building Real Games
2Buttons and Screens
Buttons and onClickLambdasWiring in the InspectorPanels On and OffHealth BarsRecap: Upgrade Shop5Saving with PlayerPrefs
Save a NumberLoad with a DefaultHigh ScoreSave SettingsRecap: Coins in the Bank3The Game Manager
One Script Runs the GameThe SingletonGame StatesSwitching on the StateRecap: Round Manager6Project: Endless Runner
Three LanesObstacles Ahead9The New Input System
Two Input SystemsKeyboard and MousePressed This FrameInput ActionsRecap: Input SwapPractice on your own: Unity playground