x


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.

more ▼

asked Feb 25 '11 at 08:20 PM

MrRstar gravatar image

MrRstar
20 6 6 11

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

so, all of a sudden, this script worked exactly like i wanted it to.

makes me kinda mad actually....

more ▼

answered Feb 25 '11 at 11:13 PM

MrRstar gravatar image

MrRstar
20 6 6 11

(comments are locked)
10|3000 characters needed characters left

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;
   }
}
more ▼

answered Feb 27 '11 at 12:33 AM

Hei gravatar image

Hei
119 2 2 7

Your script makes Unity lag When you pause it

Mar 09 '11 at 10:01 PM chrisPOD
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3690
x261
x162

asked: Feb 25 '11 at 08:20 PM

Seen: 974 times

Last Updated: Mar 09 '11 at 09:38 PM