Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Rgalaxy · Jan 17, 2014 at 06:34 PM · guigameclearpausing

Clearing a GUI and Pausing a Game

So i want to make that when first i move to this Scene, the game is paused. Until i press Start button, and all GUI cleared, and the game play again.. I've been searching all over the Answer section, yes i get a lot of good answer, but i can't done it..

So basically this is as far as i could do, and understand..

 var images : Texture2D[];//5 images
 var i : int;
 function OnGUI () {
 
     Time.timeScale= 0;
     //fungsi untuk slide tutorial next dan previous
     GUI.DrawTexture(Rect(200,50,100,100), images[i]);
     if(GUI.Button(new Rect(210,300,100,50),"next texture")){
         i++;
         if(i>images.Length-1){i=4;}
         GUI.DrawTexture(Rect(200,50,100,100), images[i]);    
         print(i);
     }
     if(GUI.Button(new Rect(100,300,100,50),"previous texture")){
         i--;
         if(i<images.Length - 5){i=0;}
         GUI.DrawTexture(Rect(200,50,100,100), images[i]);
         print(i);    
     }
     if(GUI.Button(new Rect(400,400,50,50),"Start")){
         //erase all GUI, but don't know how to do it
         Time.timeScale=1.0;
     }
 }

i think using Time.timeScale is the best and easiest way(is that true?) to pause the game.. but when i press "Start" button, the time didn't go back to play.. i mean, anything still stop .. is there anyway to achieve this?

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

1 Reply

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

Answer by stevethorne · Jan 17, 2014 at 07:50 PM

Time.timeScale is a fine way of pausing the game. The issue you're having is that you're setting Time.timeScale to 0 every single call of OnGUI. You want to set it to 0 after a certain event. For example:

 void Update()
 {
     if ( Input.GetKeyDown( KeyCode.Escape ) )
     {
         Time.timeScale = 0;
     }
 }
 
 void OnGUI()
 {
     if ( Time.timeScale == 0 )
     {
         if ( GUI.Button( new Rect( 400, 400, 50, 50 ), "Start" ) )
             Time.timeScale = 1.0;
     }
 }

This will check if you press escape and when you do, will show the gui to unpause it. Hope this helps to lead you in the right direction!

If you want the game to start paused you could move the code in Update() to your Start() function like this.

 void Start()
 {
     Time.timeScale = 0;
 }
 
 void OnGUI()
 {
     if ( Time.timeScale == 0 )
     {
         if ( GUI.Button( new Rect( 400, 400, 50, 50 ), "Start" ) )
             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 Rgalaxy · Jan 18, 2014 at 10:50 AM 0
Share

wow, it's working and i kind of understand about it now.. thanks @stevethorne could u hel me with "clearing GUI" things?

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

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How Do I Center A GUI Label? 5 Answers

How to let the player save progress 1 Answer

Ensuring Correct Call Order 0 Answers

C# Script issue with Player 1 Answer

GUI_TEXTURE PROBLEM! 2 Answers


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