The Escape Button is a Feature

Objective: Create a pause menu to allow the user to pause and exit the game.

The first thing we need to do is create the UI for the Pause menu. I made articles on this in the past. Here and here!

After the UI for the pause menu is complete, open the UI Manager script and add a private GameObject variable to and drag in the pause menu in the Unity Editor:

Now we can create a simple toggle to bring up the menu using if statements:

Switch to the Game Manager script and create a boolean to check for if the game is paused:

To actually pause the game we need to stop time to allow for a paused game state. We can do this using:

Now we need to set the “Resume” button to also call the PauseGame Method:

The last thing we need to do is allow the user to quit the game. In we don’t create a way for the player to leave then the game can’t be closed. To do this we can use:


Application.Quit when called will close the game, now we have to assign the method to the “Exit Game” button on the pause menu:

We now have a means to pause and exit our game!

Learning to become a unity game developer