GUI resume button not working?

I’ve made a simple method of pausing my game within my GameManager class as seen here:

using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour {

    private string[] levelList; //Create a list of levels

    public int playerScore;

    private bool isPaused;

    void Awake() {
        DontDestroyOnLoad(this.gameObject);
    }

	void Start () {
        isPaused = false;
        Screen.lockCursor = true;
	}
	
	void Update () {
        if (Input.GetKeyDown(KeyCode.Escape)) {
            pauseToggle();
        }
	}

    void OnGUI() {
        if (isPaused) {
            GUI.Box(new Rect(-8, -8, Screen.width + 8, Screen.height + 8), "");

            GUI.Box(new Rect(Screen.width / 2 - 160, Screen.height / 2 - 240, 320, 480), "Pause Menu");

            if (GUI.Button(new Rect(Screen.width / 2 - 120, Screen.height / 2 - 200, 120, 80), "Close Menu")) {
                isPaused = false;
                Time.timeScale = 1.0f;
                Screen.lockCursor = true;
                Debug.Log("Unpaused");
                isPaused = false;
            }

            if (GUI.Button(new Rect(20, 70, 80, 20), "Title Screen")) {
                Application.LoadLevel(1);
            }
        }
    }

    void pauseToggle() {
        if (!isPaused) {
            Time.timeScale = 0.0f;
            Screen.lockCursor = false;
            isPaused = true;
        }
        else {
            Time.timeScale = 1.0f;
            Screen.lockCursor = true;
            isPaused = false;
        }   
    }
}

The problem is that the Escape key pauses/unpauses the game perfectly, however when the pause Resume button is clicked the GUI seems to freeze yet I can still toggle the pause state with Escape to get out of it.

I’ve tried both what is current under the Buttons if statement and simply using the pauseToggle function I made earlier. I must be missing something but I can’t seem to figure it out.

Hi Once check your pauseToggle() is called on every Escape key press or print something inside pauseToggle() and one more thing you should mot useTime.timeScale instead of that you can use boolean values for pause or Resume Game.

I Think I know the problem

Do not do (!isPaused)as this is a toggle option, which conflicts with you two sets of isPaused in ONGUI (). If you remove the double then test, if that does not work - which I highly predict it will not work then change !isPaused to (isPaused == true);

I fixed it guys, just set timeScale to some ridiculously low value like 0.0000001f. Basically paused as far as normal perception is concerned. Maybe it’s a bug or not but the OnGUI function seems to mess up when timeScale is absolute zero.

Obviously, this is a late answer. However, for anyone else looking for an answer.

I had this happen with my pause script. I fixed it by going into the unity input section and found that the button it had for cancel was also Esc.

I changed that to another button (specifically to backspace, but I’m sure any other button works) and there was no longer a fight for the ESC key.