Objective: Reload the scene by pressing the “R” key on game over.
Like with the gameover text, we want a message that will pop up on gameover. We don’t want it to flicker though, so basically doing the same thing that we did here minus the flickering part will do the job just fine.
But now we want to be able to restart the whole scene by pressing “R”. To do this, we’ll need to create another empty object named GameManager, and a script for it with the same name.
Before we dive into the scripts, go to file > build settings and add the current scene to build. This scene will then get an index value of 0. This will come in handy later.
In the Game Manager script, we want to enable Scene Management. Like this:
Now we want a variable that will tell us if the game is over, and a method that will restart the scene if this variable is true and the “R” key is pressed.
This script will constantly be checking the value of _isGameOver, and that’s why we have a separate method to make it true. We’ll be calling this method when the GameOver screen is activated.
First, find the Game Manager script in the Ui Manager script, and attach it to a variable to represent it.
Now access the GameOver method.
Now everything should be working properly and ready to test out!