if (Input.GetKey(KeyCode.Escape))
{
Time.timeScale = 0.0f; // paused the game
if (GUI.Button(new Rect(230, 440, 500, 50), "QUIT")){
Application.Quit();}
else if (GUI.Button(new Rect(230, 495, 500, 50), "NO")){
Debug.Log("dont quit, hide these 2 buttons and continue playing");
Time.timeScale = 1.0f; // resumed the game
}
}
what should i write in else if, so that it returns to game scene and hide these buttons?
This will never run because it is only going to be updated when you press escape. You need to have a state that changes in your OnGUI call to display different GUI buttons.
private int guiIndex = 0;
void OnGUI()
{
switch (guiIndex)
{
case 0:
GUI.Label(testRect, "This is case 0 gui text");
break;
case 1:
GUI.Label(testRect, "This is case 1 gui text");
break;
}
}
You can then use escape to switch your guiIndex number to something else.
I’m not even sure if that pausing system works (I have yet to actually work on one, so no experience there although I have ideas) but you can also do this with a boolean value.
So:
In update, check if the Escape key is pressed. If so, change OnMenu to true (or whatever name you wish)
In the OnGUI, the entire thing for the menu will be covered in an if(OnMenu)
Make the second button to close the menu change OnMenu to false
You can also make the Escape key as well to open AND close the menu if you wish. Just make it like this: (sorry for the quick, ugly code)
Edit @Dantus: (Trying not to make an additional post) Sorry about that. I didn’t notice, and I guess trying to rush with an iffy internet connection wasn’t the best idea.