- Home /
Pause menu active when not visible
I used the code from the "Using the UI Tools" tutorial to create a pause menu for my project. In my project my pause menu has buttons on it to resume and quit the game. When you first enter the game everything works as intended, but once you activate the pause menu once it never deactivates. I can make it disappear, but I'm still able to interact with it.
By that I mean, I can pause the game by using w key and spacebar and i can quit the game by pressing s key and spacebar. Even though the pause menu isn't up and the game is being played.
From my understanding when you unpause the game the canvas is no longer enabled. So why am I still able to interact with it? Also, this only happens after the pause menu has been opened once. If I never open the pause menu the problem never occurs. Any help would be appreciated.
Here is a copy of my code:
Canvas canvas;
void Start()
{
canvas = GetComponent<Canvas>();
canvas.enabled = false;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
Pause();
}
}
public void Pause()
{
canvas.enabled = !canvas.enabled;
Time.timeScale = Time.timeScale == 0 ? 1 : 0;
}
I have experienced the same problem. enabled = false; still makes you interact with the GameObject; you should use SetActive(False);
Your answer
Follow this Question
Related Questions
GUI Menu Esc Button to Show and Hide it? 2 Answers
Pause Menu Background 1 Answer
C# problem with pause menu 2 Answers
Camera Keeps Following Mouse in Pause Menu 0 Answers
When I pause during the countdown the game does not freeze PLS SOMEONE HELP. 2 Answers