how can i add a pause menu that pops up and pause the game when i click ESC, and unpauses when i click ESC again?
I’m kinda new to unity3d so… PLEASE HELP! ![]()
how can i add a pause menu that pops up and pause the game when i click ESC, and unpauses when i click ESC again?
I’m kinda new to unity3d so… PLEASE HELP! ![]()
pausing the game:
setting Time.timeScale to 0 is often used to pause the game. And then back to whatever it was (default 1.0) when unpausing.
reacting to ESC:
function Update()
{
if( Input.GetKeyDown(KeyCode.Escape) )
{
//react to key press here
}
}
menu:
You can do it with Unity’s GUI system for example, using the OnGUI() function. This is not the optimal choice for GUIs, but could well work for pause menu’s when nothing else should be updated
to get you down the right road, lets add to Marten’s Script:
var paused=false;
function OnGUI(){
if( Input.GetKeyDown(KeyCode.Escape) ){
paused=!paused;
}
if(paused){
if (GUI.Button(Rect(10,10,50,50),"Resume"))
paused=false;
}
Time.timeScale=paused ? 0.0 : 1.0;
}
But it doesn’t happen anything when i click the esc buttom. why?
And how do i stop the mouselook script when the gui pops up?