Search Unity

Stopping time, but how?

Discussion in 'Scripting' started by robertseadog, Sep 17, 2005.

  1. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Ok So Im starting up the game with this gamescript:

    Code (csharp):
    1.  
    2.  
    3. //-- Is used at start of level1:
    4. //-- Sounds:
    5. //var backgroundMusic : AudioSource;
    6. var startText : GUIText;
    7.  
    8. //-- What happens?:
    9. function Start () {
    10. Time.timeScale = 0.0;
    11. //backgroundMusic.Stop ();
    12. //backgroundMusic.volume = 0.4;
    13. //backgroundMusic.ignoreListenerVolume = true;
    14.  
    15. yield WaitForSeconds (0.9);
    16.  
    17. startText.text = "Get Ready..";
    18.  
    19. yield WaitForSeconds (2.86);
    20. startText.text = "Set..";
    21. //-- startup:
    22. yield WaitForSeconds (2.75);
    23. startText.text = "GO GO GO!";
    24. Time.timeScale = 1.6;
    25.  
    26. //backgroundMusic.Play ();
    27.  
    28. //-- Hide text
    29. yield WaitForSeconds (0.80);
    30. startText.text = "";
    31. }
    But as you can see, The Yield thingy is time-independent! So how do I work this out?

    Thanks!
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Why do you want to set the time scale to zero at startup?
     
  3. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    I don't know, to pause the game a little while the player is getting ready..

    I guess I could just set all rigidbodies in my scene to not be active, but I would rather have a single method of pausing everything.

    Does it make sense?
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Yeah your way is probably the least hassle in the long run.


    I will add Time.realtimeSinceStartup to version 1.1.1 which returns time independent of time scale.

    You wont be able to use coroutines when setting timescale to zero, so you have to do it the old fashioned way overriding function Update () {}.

    You have to store when you started the game in a variable. Then inside Update you check if Time.realtimeSinceStartup has progressed far enough to let the game begin.
     
  5. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    Hmm.. I guess I just have to wait until 1.1.1 then! :roll:
     
  6. BasketQase

    BasketQase

    Joined:
    Sep 12, 2005
    Posts:
    97
    I've been playing with the v1.1.1b1 release a bit today and I just found that Unity no longer allows me to set Time.timeScale to 0.

    Is there an alternate way to stop the game in the case of a pause menu or something similar? Most of our project is physics-based and stopping time was an elegant solution to the problem. Is there another way to turn off physics calculations globally?

    -rob
     
  7. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Sorry that is a bug in 1.1.1b1.
    Thanks. I'll fix it for 1.1.1
     
  8. BasketQase

    BasketQase

    Joined:
    Sep 12, 2005
    Posts:
    97
    Great, thanks.

    When do you expect to have a build with that fix available?

    -rob
     
  9. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    1.1.1 is scheduled for monday, with another beta build tomorrow.

    (Note that this bug is only in 1.1.1b1 not in 1.1)
     
  10. BasketQase

    BasketQase

    Joined:
    Sep 12, 2005
    Posts:
    97
    Sweet!

    Yeah, I was using 1.1 until yesterday. I was curious because our project is on a short timeframe so I wanted to get an idea of whether to go back to 1.1 or work on other things if that fix would be available before we planned to have our game finished.

    Thanks for the quick replies! It's great that you guys update Unity so quickly, too.

    -rob