Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Time.timeScale not working

Discussion in 'Scripting' started by karammaks, Jul 6, 2014.

  1. karammaks

    karammaks

    Joined:
    Apr 6, 2014
    Posts:
    146
    Hi
    i am using Time.timeScale=0; in my code but its not working even if i put it in the void Update

    Code (CSharp):
    1. void Update(){
    2.          if (Score < 0) {
    3.             Time.timeScale=0;
    4.                        
    5.                 }
    6.         }
    if i put anything else in that if condition it works , but i dont know why it doesn't pause my game :S
     
  2. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    669
    My first guess is that you possibly want to use <= instead of < in case Score's minimum is 0.
     
  3. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Well, I know there is some funky call to be made that I can't find right now, if, you are running coroutines. Something like yield WaitForSeconds. However, if you are just using update, put a breaker in, if timescale ='s 0, return.
     
  4. karammaks

    karammaks

    Joined:
    Apr 6, 2014
    Posts:
    146
    I cant use <=0 , because game starts from 0
     
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,680
    Again,
    If you are just using update, not coroutines...

    Code (csharp):
    1.  
    2. void Update(){
    3. if(Time.timeScale == 0)
    4. return;
     
  6. Pysassin

    Pysassin

    Joined:
    Dec 27, 2012
    Posts:
    87
    Not enough information in this post for anyone to fix your problem. You show us/explain NOTHING in your game that is time dependent. Generally the ONLY things you'll have in your project this affects is things in Fixed Update and things multiplied by Time.deltaTime. If what you are trying to affect is under neither category it could very well be the source of your woes.
     
  7. karammaks

    karammaks

    Joined:
    Apr 6, 2014
    Posts:
    146
    its 2d game , with spawners that spawn object and trigger to catch them , some object give minus score , so when score becomes less than 0 , i want to stop the game and show game over scene or window
     
  8. Pysassin

    Pysassin

    Joined:
    Dec 27, 2012
    Posts:
    87
    I understand that but for it to give the "paused effect" everything you want to stop needs to some how be manipulated by time. If you use translations via update loop without affecting them with Time.deltaTime (which is a horrible habit to get into) then they wouldn't be affected by the timescale change. Need to see how you've coded some of the things you want paused.