Let's add an overloaded version of RestartLevel():
- Open up Utilities and add the following code:
public static class Utilities
{
public static int playerDeaths = 0;
public static void RestartLevel()
{
SceneManager.LoadScene(0);
Time.timeScale = 1.0f;
}
// 1
public static bool RestartLevel(int sceneIndex)
{
// 2
SceneManager.LoadScene(sceneIndex);
Time.timeScale = 1.0f;
// 3
return true;
}
}
- Open GameBehavior and update one of the calls to Utilities.RestartLevel() in the OnGUI() method to the following:
if (showWinScreen)
{
if (GUI.Button(new Rect(Screen.width/2 - 100,
Screen.height/2 - 50, 200, 100), "YOU WON!"))
{
// 4
Utilities.RestartLevel(0);
}
}
Let's break down the code:
- First, it declares an overloaded version of the RestartLevel() method that takes in an int parameter and returns...