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
1
Question by Rayan Adam · Nov 12, 2012 at 03:20 PM · c#yieldtimescaleresume

wait 3 seconds then resume c#

hello ...

am trying to pause my game using time.timescale=0 ... but when i want to resume my game after 3 seconds it doesn't work as i followed this solution: http://answers.unity3d.com/questions/9878/freeze-game-using-timetimescale-0-wait-3-secs-and.html

and here is my code :

 private IEnumerator Pause(int p)
 {
     Time.timeScale = 0.1f;
     float pauseEndTime = Time.realtimeSinceStartup + 1;
     while (Time.realtimeSinceStartup < pauseEndTime)
     {
         yield return 0;
     }
     Time.timeScale = 1;
 }
 
 void ButtonUp()
 {    
     StartCoroutine( Pause() );
     guiTexture.texture = ResumeBtn;
     PauseButton.guiTexture.texture = PauseBtn;
     PauseMenu.gameObject.SetActiveRecursively(false);
 }

it resumes the game but with time.timescale = 0.1f only ... any ideas

Comment
Add comment · Show 3
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 FakeBerenger · Nov 12, 2012 at 03:22 PM 0
Share

It should work. Try to yield null ins$$anonymous$$d of 0, and print Time.realtimeSinceStartup to check if it increases.

avatar image Owen-Reynolds · Nov 12, 2012 at 03:52 PM 0
Share

"it resumes the game but with time.timescale = 0.1"

What do you mean by "resumes"? When you click, the time scale should snap to 0.1 (is this a test value, which will become 0 when it's working?) If it never goes back to 1, I think it is NOT resu$$anonymous$$g.

avatar image Rayan Adam · Nov 12, 2012 at 04:34 PM 0
Share

FakeBerenger you gave me the solution thanks :)

Owen Reynolds i mean it the script is stopping on the line where Time.timscale = 0.1f; but i solved it :) thanks for your time

3 Replies

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

Answer by Rayan Adam · Nov 13, 2012 at 05:55 PM

I already solved it thanks :

void Awake(){ first = 0; second = 0; third = 0; resumeIn3Seconds = false; }

     void Update()
     {
         ResumeIn3Seconds();
     }
     
     void ResumeIn3Seconds(){
         if(resumeIn3Seconds){
             Counter123.active = true;
             StartCoroutine(ResumeAfterSeconds(3));
         }
     }
            
     private IEnumerator ResumeAfterSeconds(int resumetime) // 3
     {
         Time.timeScale = 0.0001f;
         float pauseEndTime = Time.realtimeSinceStartup + resumetime; // 10 + 4 = 13
         
         float number3 = Time.realtimeSinceStartup + 1; // 10 + 1 = 11
         float number2 = Time.realtimeSinceStartup + 2; // 10 + 2 = 12
         float number1 = Time.realtimeSinceStartup + 3; // 10 + 3 = 13
         
         while (Time.realtimeSinceStartup < pauseEndTime) // 10 < 13
         {
             if(Time.realtimeSinceStartup <= number3)      // 10 < 11
                 Counter123.guiTexture.texture = Three;
             else if(Time.realtimeSinceStartup <= number2) // 11 < 12
                 Counter123.guiTexture.texture = Two;
             else if(Time.realtimeSinceStartup <= number1) // 12 < 13
                 Counter123.guiTexture.texture = One;
             
             yield return null;
         }
         Counter123.active = false;
         resumeIn3Seconds = false;
             Time.timeScale = 1;
     }
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 Montraydavis · Nov 13, 2012 at 02:06 PM

 yield WaitForSeconds ( 3 ) ; // Just don't add it to Update. Use a co-routine.
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 Rayan Adam · Nov 13, 2012 at 04:29 PM 0
Share

i tried this but it doesn't work when timScale = 0

avatar image
1

Answer by Karsnen_2 · Nov 13, 2012 at 05:06 PM

Can't you just pause the game and then Invoke a function to change the TimeScale value, 3 seconds later.

Something like this.

   void Update ()
             {
                 // When you need to
                 pauseGame ();
                 Invoke("pauseGame",3.0f);
             }
             
         void pauseGame ()
         {
             if(Time.timeScale == 1f)
                 Time.timeScale = 0f;
             else Time.timeScale = 1f;
         }
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 andiCR · Feb 18, 2015 at 05:32 PM 0
Share

Unfortunately, this uses the timescale to call the Invoke method as well, so no, it won't work :)

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

13 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

Related Questions

Time.timeScale doesnt work with GUI? 0 Answers

Can't set Time.timeScale back to 1. 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

GUI resume button not working? 4 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