- Home /
Problem with code running sequence
I have a singleton called GameManager. Basically, I have a pause menu object for all the GUI code. And I want to press escape while in the options menu, to go back to the pause menu and not removing the whole pause menu.
In the GameManager's Update function, I have something like this:
// Activate/deactivate pause menus
if(isGamePaused)
{
// Sadly we have to find every frame the pausemenu object (temporary)
GameObject pauseMgr = GameObject.Find("PauseMenuManager");
if(pauseMgr)
{
PauseMenuManager pausemenu = pauseMgr.GetComponent<PauseMenuManager>();
// Remove the game object if we are done
if(pausemenu && pausemenu.IsBasePauseMenu())
{
UnPause();
}
}
}
else // Want to show the base pause menu
{
Pause();
}
But the thing is, IsBasePauseMenu() returns true everytime. I even made the GUI code in my PauseMenuManager gameobject to skip a frame before setting the boolean to return True. So it seems to be like my OnGUI function is being called several times in a row before Unity moves on to execute my GameManager's Update()? I even tried the Script Execution Order, but it seems to be of no use as well.
Any idea why and/or how to solve this? The option I have left is to somehow "eat" the Escape key trigger for the pausemenu's gui side, so that the GameManager won't be able to detect that the Escape key has been triggered. If that is even possible.