I’m trying to put a GUIButton that only appear when the GameOver() function is called after the player dies, which when pressed will reset the high score to 0; by changing the PlayerPrefs value. I can get it so that the button apepars and works, but it is there at the start. It doesn’t appear at Gameover like I want. Here’s what I’ve got
using UnityEngine;
using System.Collections;
public class GameController : MonoBehaviour
{
private bool gameOver;
private bool restart;
private bool canReset;
private int score;
void Start ()
{
gameOver = false;
restart = false;
score = 0;
canReset = false;
StartCoroutine (SpawnWaves ());
}
void Update ()
{
if (restart)
{
if (Input.GetKeyDown (KeyCode.R))
{
Application.LoadLevel (Application.loadedLevel);
}
}
if(canReset)
{
OnGUI ();
}
}
IEnumerator SpawnWaves ()
{
if (gameOver)
{
restart = true;
break;
}
}
public void GameOver ()
{
gameOver = true;
canReset = true;
}
void OnGUI()
{
if(GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 50, 200, 50), "Reset High Score"))
{
PlayerPrefs.SetInt("HighScore", 0);
}
}
}
If my code looks a little off, that is because I removed a bunch of stuff for the sake of shrinking it down for this question. I think I need to change something in OnGUI() but I don’t know what. Any suggestions? Thanks guys!