- Home /
Pause Button Problems
so i'm in a scripting class and we are making a simple game. we are adding a pause button and i'm having trouble. i have it to the point where the GUI.toggle button shows up and pauses the game when you click it but i can't get it to unpause. when you pause the game all of the GUI dissapeares like its supposed to, i just don't know how to make it so that you can up pause it. Here is my script:
var theButtonWidth:int; var theButtonHeight:int; var theButtonSpace:int; var thePauseButton = false; var gamePaused : boolean = false; var theRate = 1;
var labelwidth: int; var labelheight: int;
static var theCashCount: int; static var theAmmoCount: int; static var theHealthCount: int;
function OnGUI (){ if (theRate !=0) { GUI.Box (Rect (Screen.width*.75,Screen.height*.88-(labelheight+theButtonSpace)2, labelwidth, labelheight), "Health Amount: " + theHealthCount); GUI.Box (Rect (Screen.width.75,Screen.height*.88-(labelheight+theButtonSpace), labelwidth, labelheight), "Cash Amount: " + theCashCount); GUI.Box (Rect (Screen.width*.75,Screen.height*.88-(labelheight+theButtonSpace)*3, labelwidth, labelheight), "Ammo Amount: " + theAmmoCount);
var weaponSwitchButton = GUI.Button (Rect (Screen.width*.1,Screen.height*.88, theButtonWidth, theButtonHeight+theButtonSpace), "Weapon Switch");
if(weaponSwitchButton){
print("Changed Weapon");
}
var thePauseButton = GUI.Toggle (Rect ((Screen.width)-((theButtonWidth*3)+(theButtonSpace*4)), theButtonSpace, theButtonWidth, theButtonHeight), thePauseButton, "Pause");
if(thePauseButton){
print("Pause");
PauseTheGame (0);
gamePaused = true;
}
else{
PauseTheGame (1);
gamePaused = false;
}}
else if (Input.GetKeyDown(KeyCode.Space) && gamePaused)
{
PauseTheGame (1);
gamePaused = false;
}
}
function PauseTheGame (theRateScale){ Time.timeScale = theRateScale; Time.fixedDeltaTime= theRateScale; theRate = theRateScale; }
i've tried a few things like attempting to add an unpause with a GetKey and the like, but it doesn't ever seem to work exactly right. i've had it where it will print pause and resume in the console but won't actually pause.
Answer by MrRstar · Feb 25, 2011 at 11:13 PM
so, all of a sudden, this script worked exactly like i wanted it to.
makes me kinda mad actually....
Answer by Hei · Feb 27, 2011 at 12:33 AM
This script is ok
var thePauseButton = false;
function OnGUI () { thePauseButton = GUI.Toggle (Rect (100,50,100,30), thePauseButton, "Pause"); if (thePauseButton) { Debag.Log("Pause"); Time.timeScale = 0.0; } else { Debag.Log("Play"); Time.timeScale = 1.0; } }
Your answer
Follow this Question
Related Questions
Toggle GuiTexture 1 Answer
Can I have toggle buttons in a selection grid? 1 Answer
How does GUI.Toggle work? 2 Answers
Actually do something with GUI selection grid 1 Answer
Toggle GUITexture V.2 1 Answer