Restarting our scene after game over | Unity 2D

Chelsea Cruise
3 min readJun 23, 2021

Objective: Press a key on the keyboard to reboot our scene.

For starters, let’s go into our UIManager and create a variable for our restart text and serialize the field so we can change it later in the inspector.

Assign it in the inspector by attaching it to the UIManager.

Next, I’ll create a new script called “GameManager”. I will add a new library to my script called “SceneManagement”. This holds code that will help me reload my game.

You can see more on how to do this by reading up on the documentation.

In our update method, I will call an if() statement to check if we are pressing the keyboard & our game is over. If so, using our SceneManagement library it will reload our Game scene. This is labeled exactly “Game”, however, we could have used the index number to call our new scene as well.

I also added a new method to our script called Game Over() to check if our game is over so we can press the keyboard.

If we run the game now we will get an error. That’s because we need to add out scene to our build settings.

Now, in our UIManager script I will create a handle to call my Game Over method in the game manager script.

In the start method, call the handle:

Now we can access the game over method in the game manager script like so:

Let’s run our game and test this out!

--

--

Chelsea Cruise

Unity Developer, Software Engineer, Game Designer, Graphic Artist