To refactor the existing level's restart code, you'll need to update GameBehavior, as follows:
public class GameBehavior : MonoBehaviour
{
// ... No changes needed ...
// 1
void RestartLevel()
{
SceneManager.LoadScene(0);
Time.timeScale = 1.0f;
}
void OnGUI()
{
GUI.Box(new Rect(20, 20, 150, 25), "Player Health: " +
_playerLives);
GUI.Box(new Rect(20, 50, 150, 25), "Items Collected: " +
_itemsCollected);
GUI.Label(new Rect(Screen.width / 2 - 100, Screen.height -
50, 300, 50), labelText);
if (showWinScreen)
{
if (GUI.Button(new Rect(Screen.width/2 - 100,
Screen.height/2 - 50, 200, 100), "YOU WON!"))
{
// 2
RestartLevel();
}
}
if(showLossScreen)
{
if...