Hello. I’ve been going crazy over this all day. I need some help.
I have a very simple scene set up: 3 UI buttons parented to an empty GameObject (let’s call it the Pause Menu) which is parented to a Canvas. A script is attached as a component to the Canvas as well as the Resume and Quit buttons. Here it is:
using UnityEngine;
using System.Collections;
public class MainScript : MonoBehaviour
{
public bool isPaused = false;
public GameObject pauseMenu;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetButtonDown("Cancel"))
{
Debug.Log("Paused / Unpaused");
TogglePause();
}
}
public void TogglePause()
{
if (!isPaused)
{
isPaused = true;
pauseMenu.SetActive(true);
Time.timeScale = 0;
}
else if (isPaused)
{
isPaused = false;
pauseMenu.SetActive(false);
Time.timeScale = 1;
}
}
public void OnQuit()
{
#if UNITY_STANDALONE
Application.Quit();
#endif
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#endif
}
}
You can toggle pause/unpause using the Escape key to show/hide the Pause Menu GameObject. One of the buttons is “Resume” and it does the exact same thing as unpausing with the Escape key once it’s already paused.
Toggling the Pause Menu works flawlessly if you use the Escape key but as soon as you press the Resume button (which for some reason, you have to click twice) you have to press Escape twice to bring up the Pause Menu again. And then you keep having to click the Resume button twice to unpause. Please help, it’s driving me crazy.
I am using Unity v5.3.5f1 Personal Edition. I also attached the project as a zip file if you need to look into the scene yourself.
Thank you very much for taking an interest in my issue. Looking forward to your replies.
2668149–188240–TESTproject.zip (908 KB)