Unity/C# Challenge 17: Loading Scenes in Unity

Alec Oney
Jul 20, 2021

Challenge: Restart our game using SceneManager.

Right now, we have our game over scene set:

We now want to put in the code that will allow us to restart. First, we create a GameManager object (empty) and attach a new script. Then, we update the script to run our restart code:

and update our player script relating to lives:

Finally, and most importantly, in our game manager script, we need to include the scene management libraries:

This will allow our code to work with respect to the SceneManager.LoadScene command.

Now, when we press “R”, the scene (“Game” in this case) will reset. You may have to add your scene by pressing Add Open Scenes button in the build settings (File > Build Settings)

--

--