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:
- 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();
- 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...