Restarting the game

There may come a time in a game when a player makes a mistake and would like to restart the level in the game they're currently playing. If you prepared your project ahead of time like we have, it's actually quite easy to get this functionality placed into your game. With that being said, let's implement that functionality now! We will perform the following steps:

  1. Open up the PauseMenu script and add the following highlighted code:
    GUILayout.BeginHorizontal();
    
        if (GUILayout.Button ("Resume")) 
        {
          //resume the game
          isPaused = false;
        }
    
        if (GUILayout.Button ("Restart")) 
        {
          Application.LoadLevel(Application.loadedLevelName);
        }
        GUILayout.EndHorizontal();
    
  2. Once finished, save your file and move back into Unity and play the game! ...

Get Unity Game Development Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.