Journal 23 — Load Scenes in Unity

Chris Nielsen
2 min readMay 6, 2021

The last part of the examples on my first implementation of UI follows the two previous journals, and allows the player to restart the game by pressing the ‘R’ key.

We first need an empty game object called Game Manager and a C# script attached. A Game Manager can be used for several actions in a game, including: keep track of what state the game is in, manage the menu/pause systems, record and store information for various purposes (audio/video settings, control bindings, game save data).

Unity Hierarchy with Game_Manager game object added

In the GameManager script, we need to access the SceneManagement namespace in order to access commands such as SceneManager.

GameManager script with SceneManagement namespace added

In order to use the SceneManager and LoadScene commands, we need to update the Build Settings and make sure the Scenes are part of the build. In this case we are starting out with one level, that has an Index of 0.

Unity updated build settings

We will put in the Update method a restart check which only works if a bool is set to true that the game is over. This public void method is called in the UI Manager function GameOverSequence.

UIManager script game over sequence that game over check in GameManager
GameManager script that allows for restart
Unity Playmode, restart works!

Thank you for your time!

--

--

Chris Nielsen

An Engineering Manager consultant who is seeking additional skills using Unity 3D for game and application development.