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 RevolverOctorok · Apr 14, 2015 at 10:24 PM · timedelaytimescalepause menuunpause

Delaying Time.timeScale =1 when unpausing (to allow time for animation to clear)

I know there are a LOT of time related questions on this board, and I swear I've read every last one of them. I've been searching and trying things for 3 hours now with no luck. With that said, here's my problem.

When I pause the game, I set Time.time = 0, everything is gravy. When I resume, the animation for my pause menu takes just a split second to clear, but this is a fast paced game so I want time.timeScale to still = 0 for a half second after unpausing in order for the animation to clear. Here's what I have so far that ALMOST works:

 public void ReseumeGame() {
     StartCoroutine (Resuming());
     unPauseSound.Play ();
     pauseMusic.Stop ();
     backgroundMusic.UnPause ();
 }

 IEnumerator Resuming(){
     float pauseTime = Time.realtimeSinceStartup + 3f;
     Debug.Log ("Before wait.");
     while (Time.realtimeSinceStartup < pauseTime)
     {
         yield return 0;
     }
     Debug.Log ("After wait."); // Waits 3 seconds like it should.
     Time.timeScale = 1; // Executes immediately without waiting!!! >_<
     pauseButton.SetActive (true); // Waits 3 seconds like it should.
 }

I'm using 3 seconds here just to make the delay obvious. As it stands right now, upon unpausing, before wait is displayed, Time.timeScale = 1 executes, 3 seconds passes, after wait displays, and the pause button is set active again... meaning everything is delayed like I want it to be EXCEPT FOR TIME.TIMESCALE=1. Is that function somehow immune to delays? I'm not sure how the Debug.Log("After wait.") and pauseButton.SetActive(true); that is before and after Time.timeScale = 1 can be delayed without the Time.timeScale = 1 being delayed as well.

Any help would be immensely appreciated, I'm losing hairs over this.

Comment
Add comment · Show 2
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 RevolverOctorok · Apr 14, 2015 at 07:09 PM 0
Share

Approve me please! :(

avatar image RevolverOctorok · Apr 14, 2015 at 11:40 PM 0
Share

Has anyone else ever run into this before? I can't be the only one who has tried delaying this... :P

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Olgo · Apr 14, 2015 at 11:57 PM

I dropped your code onto a gameobject in one of my scenes and it works perfectly. I had to make a couple adjustments because I dont have music playing components set up. but it works exactly as it should as follows.

I'm not sure what your pauseButton.setActive(true) is about. I commented that out because I dont have the supporting code. It seemed weird though because on resuming, wouldn't you want your pauseButton.setActive to be false? Just seems counter intuitive. maybe theres an issue there?

However the time scaling works perfectly.

 using UnityEngine;
 using System.Collections;
 
 public class test : MonoBehaviour {
 
     void Start(){
         Time.timeScale = 0;
     }
 
     void Update(){
         if (Input.GetKeyUp (KeyCode.Space)) {
             ReseumeGame();    
         }
     }
 
     public void ReseumeGame() {
         StartCoroutine (Resuming());
         //unPauseSound.Play ();
         //pauseMusic.Stop ();
         //backgroundMusic.UnPause ();
     }
     
     IEnumerator Resuming(){
         float pauseTime = Time.realtimeSinceStartup + 3f;
         Debug.Log ("Before wait.");
         while (Time.realtimeSinceStartup < pauseTime)
         {
             yield return 0;
         }
         Debug.Log ("After wait."); // Waits 3 seconds like it should.
         Time.timeScale = 1; // Executes immediately without waiting!!! >_<
         //pauseButton.SetActive (true); // Waits 3 seconds like it should.
     }
 }
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 RevolverOctorok · Apr 15, 2015 at 12:42 AM 0
Share

After quitting in frustration last night... I just tried it again and you're right, now it works >_< I have no idea why it wasn't working last night. $$anonymous$$ust have been a strange Unity bug (though I even tried restarting Unity last night to see if it was a bug). $$anonymous$$aybe the update somehow helped? Lol, I dunno. Very strange.

Thanks for trying it out though!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Problem changing TimeScale 1 Answer

How to Appease a pause menu in a game that changes it's time scale? 1 Answer

Pause, Unpause 1 Answer

Javascript Timescale Problem 0 Answers

Can i ignore timescale when playing AudioSource.PlayClipAtPoint ? 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