Book Image

Unity Game Development Blueprints

By : John P. Doran
Book Image

Unity Game Development Blueprints

By: John P. Doran

Overview of this book

Table of Contents (16 chapters)
Unity Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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! The following screenshot depicts the game screen:

Simple enough! We've now added a new button to our menu and when we click on it, we load the currently loaded level.

Note

If you use this implementation in your...