“Next Chapter Please!” How to Load New Scenes in Unity.
Objective: Explain how to load a new scene in Unity.
As you develop your project, you will eventually have multiple Scenes to navigate through.
In the example below, we have a typical Main Menu screen, as well as the default Scene depicting the first level of the game.
The first step is to go into the Build Settings and ensure all your desired Scenes are included in your build. Get there by navigating “File” then “Build Settings…”. You do this by having the Scene open in Unity, then selecting “Add Open Scenes”. Doing so will list your Scenes and assign an index number (on the right side) associated with each Scene.
Then, in order to use the class required to manage your scenes at run time, you need to add the namespace “using UnityEngine.SceneManagement;”.
In the case of my project, once my player has lost all of his lives, the UI Manager will flash the GAME OVER text, and turn on notifications at the bottom of my screen directing the user to select an option to either restart the game, or return to the Main Menu.
I then use the following code in my GameManager class in order to detect keyboard inputs (letter R or M). This will in turn tell my SceneManager class to use the Static Method LoadScene to reload the Main Menu (index 0), or restart the game (index 1).
As you can tell, loading a new Scene in Unity can be fairly simple. I hope this quick little reference will at a bare minimum help you with your project, as well as point you to the official references for further study. Thanks for reading :)