I have a pause menu that gets activated when pressing Escape. In that menu I have a series of buttons that when clicking on, close the previous menu and open a new panel with the option of going backwards. The thing is that if I press Escape once inside of the second panel, the initial pause menu overlays. My intention is to block the key Escape when the second menu is on, so it doesn’t happen but I don’t know how
Any clues/method I could try?
Can you please show the code? It would help a lot.
Here’s my advice without seeing the code though…
Create an enum and call it PauseState.
This enum should have as many states as there are panels… So if you have the MainPause panel and a settings panel, then make sure the enum has “Main” and “Settings” as possible states.
public enum PauseState
PauseState myState = PauseState.Main;
Now, whenever you click on the button for settings, simply set myState to PauseState.Settings.
public void SettingsButton()
// Turn off the main panel
// Turn on the settings panel
// We're now in the settings menu
myState = PauseState.Settings;
That way, when you press Escape, you can check if myState is Main or not.
// If we press Escape
// If we're currently paused
// If we're on the main panel
if(myState == PauseState.Main)
// Unpause the game
// If we're not currently paused
// Pause the game
Thank you for your answer @Darkforge317 :D,
I understand that my problem can be a little bit confusing, that’s why I did these gifs to try to show better what is the issue I am facing. Here you can see how I access the game and when pressing Escape and accessing the audiosettings the pause menu overlays the audio settings menu. This is what I am trying to avoid.
As you can see in my Hierarchy I have different panels and I change between them by using the OnClick() options setting active or unactive their visibility.
To fix the problem with the Escape I was trying to play with the interactability and alpha map of the PausePanel. This is how I did a script called BlockEscape that reads like this:
public CanvasGroup pausePanel;
public bool subMenuClicked = false;
if (subMenuClicked == false)
pausePanel.alpha = 1;
pausePanel.interactable = true;
pausePanel.blocksRaycasts = true;
pausePanel.alpha = 0;
pausePanel.interactable = false;
pausePanel.blocksRaycasts = false;
however that works half way because although it avoids the overlay, it doesn’t show the pause panel menu anymore after leaving the audio settings even if I press Escape. Check the following gif:
I don’t know what to do next.