what do i add to this script to make my game pause?
/* GUI.Pause example */
function OnGUI () { if (GUI.Button (Rect (25, 25, 100, 30), "Pause")) { // This code is executed every frame that the Pause remains clicked } }
what do i add to this script to make my game pause?
/* GUI.Pause example */
function OnGUI () { if (GUI.Button (Rect (25, 25, 100, 30), "Pause")) { // This code is executed every frame that the Pause remains clicked } }
Take a look at this answer: http://answers.unity3d.com/questions/15963/pause-button-script
Basically, you want to set:
Time.timeScale = 0.0;
to pause and :
Time.timeScale = 1.0;
To resume.
My In Game Pause Menu.
There is a button to activate it up in the Upper Right hand cornor and you can press āPā to bring it up hope you all enjoy if you want to change were the main menu takes you just change it to the level you want it in the build settings you can get the number it is on line 22
var paused : boolean = false;
if(GUI.Button(Rect(1835,20,80,20),"Pause"))
{
paused = true;
}
if(Input.GetKey("p"))
{
paused = true;
}
if(paused == true)
{
GUI.Box(Rect(810,75,300,400),"Menu");
if(GUI.Button(Rect(920,100,80,20),"Resume"))
{
paused = false;
}
if(GUI.Button(Rect(920,130,80,20),"Main Menu"))
{
Application.LoadLevel(0);
}
if(GUI.Button(Rect(920,160,80,20),"Quit"))
{
Application.Quit();
}
}
if(paused == true)
{
Time.timeScale = 0;
}
if(paused == false )
{
Time.timeScale = 1;
}