Let's create a new class to hold some of our future methods that deal with raw computations or repeated logic that doesn't depend on the gameplay:
- Create a new C# script in the Scripts folder and name it Utilities.
- Open it up and add the following code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 1
using UnityEngine.SceneManagement;
// 2
public static class Utilities
{
// 3
public static int playerDeaths = 0;
// 4
public static void RestartLevel()
{
SceneManager.LoadScene(0);
Time.timeScale = 1.0f;
}
}
- Delete RestartLevel() from GameBehavior and modify the OnGUI() method with the following code:
void OnGUI()
{
// ... No other changes needed ...
if (showWinScreen)
{
if (GUI.Button(new Rect(Screen.width/2 - 100,
Screen.height/2 - 50, 200, 100), "YOU WON!"))
{
// 5
...