- Home /
Pause Button Script
Hi, I am almost finished my game, but I still want a button to pause and unpause my game. I want it to be a .GUI button if you can. Please help! Thank you!
Here is a tutorial that $$anonymous$$ches you how to do that: http://youtu.be/z5oA-DvVGoo
Answer by Julian-Glenn · Jul 20, 2010 at 07:54 PM
First search for Pause revealed this:
http://answers.unity3d.com/questions/15262/end-pause-game
Try click on the tag Pause or search as it helps keep the site cleaner :)
Here is a script that creates a pause/continue/quit GUI attach it to the Camera in your scene, or any GameObject with a GUILayer component attached.
var guiSkin: GUISkin; var nativeVerticalResolution = 1200.0; var isPaused : boolean = false;
function Update() {
if(Input.GetKeyDown("escape") && !isPaused)
{ print("Paused"); Time.timeScale = 0.0; isPaused = true; } else if(Input.GetKeyDown("escape") && isPaused) { print("Unpaused"); Time.timeScale = 1.0; isPaused = false;
} }
function OnGUI () {
// Set up gui skin
GUI.skin = guiSkin;
// Our GUI is laid out for a 1920 x 1200 pixel display (16:10 aspect). The next line makes sure it rescales nicely to other resolutions.
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.height / nativeVerticalResolution, Screen.height / nativeVerticalResolution, 1));
if(isPaused)
{
// RenderSettings.fogDensity = 1;
if(GUI.Button (Rect((Screen.width)/2,480,140,70), "Quit", "button2"))
{
print("Quit!");
Application.Quit();
}
if(GUI.Button (Rect((Screen.width)/2,560,140,70), "Restart", "button2"))
{
print("Restart");
Application.LoadLevel("SomeLevelHere");
Time.timeScale = 1.0;
isPaused = false;
}
if(GUI.Button (Rect((Screen.width)/2,640,140,70), "Continue", "button2"))
{
print("Continue");
Time.timeScale = 1.0;
isPaused = false;
}
}
}
@script AddComponentMenu ("GUI/Pause GUI")
When I put the script in the camera and play the game, I get a ton of errors...Please help.
hi luketheboss03. As the scripts are put into the camera without playing. There was no mistake, I run and I'm still using the same. :S :S :S
Answer by kchrysanthis · Nov 14, 2012 at 07:49 PM
what kinda script is it? Can we get the full code pls =)
Answer by Kurt P · Mar 22, 2011 at 08:48 PM
This isn't an answer but you can change whether or not you want to exit the application with the quit button or if you want to make your player go to a main menu all you do is change this part Application.Quit(); and so change it to this Application.LoadLevel("name of main menu here");
Answer by nurullah us · May 04, 2015 at 10:36 AM
I hope it helps you :) js coce! Take it into the camera.
#pragma strict
var pause : boolean = false;
function OnGUI()
{
if (GUI.Button (Rect(Screen.width-55,60,50,50),"Pause"))
{
if (pause == false)
{
pause = true ;
Time.timeScale = 1 ;
return;
}
if (pause == true)
{
pause = false;
Time.timeScale = 0 ;
return;
}
}
}
Your answer
Follow this Question
Related Questions
In game pause menu 2 Answers
When i press play it just pauses right after. 6 Answers
Pause Menu - Loading & Quitting 1 Answer
Transitions When Pausing? 1 Answer
Audio problem 1 Answer