Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MrRstar · Feb 25, 2011 at 08:20 PM · guipausetoggle

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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....

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image chrisPOD · Mar 09, 2011 at 10:01 PM 0
Share

Your script makes Unity lag When you pause it

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges