Search Unity

Unity 2017 timescale=0 not working please help me

Discussion in 'Scripting' started by Mucossa, Feb 28, 2018.

  1. Mucossa

    Mucossa

    Joined:
    Feb 25, 2018
    Posts:
    34
    hello. i'am tried unity version 5.3.2 is timeScale=0 function working and trying unity 2017.x.x version is not working. please help me.

    this code ;

    Code (CSharp):
    1.  using UnityEngine;
    2. using System.Collections;
    3. public class paused : MonoBehaviour {
    4.      public static bool GameIsPaused = false;
    5.    
    6.      public GameObject pauseMenuUI;
    7.    
    8.      void Update () {
    9.          if(Input.GetKeyDown(KeyCode.Escape))
    10.          {
    11.              if(GameIsPaused)
    12.              {
    13.                  Resume();
    14.              } else
    15.              {
    16.                
    17.                  Pause();
    18.              }
    19.          }
    20.      }
    21.      void Resume()
    22.      {
    23.          pauseMenuUI.SetActive(false);
    24.          Time.timeScale = 1;
    25.          GameIsPaused = false;
    26.      }
    27.      void Pause()
    28.      {
    29.          pauseMenuUI.SetActive(true);
    30.          Time.timeScale = 0;
    31.          GameIsPaused = true;
    32.      }
    33. }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,749
    Do you possibly have the above script on more than one GameObject? Or perhaps two copies of the script on the same GameObject?
     
    Mucossa likes this.
  3. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    I've had no problems with timescale adjustment on 2017.

    When you say that it isn't working, could you be more specific? Like what do you expect to happen, and what actually happens?
     
  4. Mucossa

    Mucossa

    Joined:
    Feb 25, 2018
    Posts:
    34
    i am pause menu creating. pause menu opening but does not stopping game. unity 5 is same project in same code is working. but a unity 2017 is same code same project but is does not working
     
  5. Mucossa

    Mucossa

    Joined:
    Feb 25, 2018
    Posts:
    34
    code inside the single GameObject. and no other copies
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,749
    Perhaps try commenting out the lines that call pauseMenuUI.SetActive(true); and pauseMenuUI.SetActive(false); ... there could be some other component inside that hierarchy that changes Time.timeScale...
     
    Mucossa likes this.
  7. Mucossa

    Mucossa

    Joined:
    Feb 25, 2018
    Posts:
    34
    I did not understand why.
    I'm a little unlucky such interesting problems always come to me :)
    .
     
  8. Mucossa

    Mucossa

    Joined:
    Feb 25, 2018
    Posts:
    34
    tested code in unity 2017.2.2 is working. unity 2017.3.x version is not working pause script.
     
  9. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    So you have made sure that there is 1 single instance of this script, and your not getting any console errors when it runs, and the same identical code seems to work in other unity versions.

    Sounds like a bug, but I think you should setup a test where you open a new blank project, place a physics object in the scene so that when you hit play, the rigidbody object falls downwards. Then attach a script to your camera or a blank object, which ONLY sets the timescale to a different number (perhaps you should try something like 0.01) and see if the box still moves. If you set the timescale to 0, and the physics object does not fall, then you know that setting timescale is actually working, and its something related to your project or the other scripts code.

    I'd use a simple test like this where physics should occur very slowly:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class TestTimescale : MonoBehaviour
    4. {
    5.     void Start()
    6.     {
    7.         Time.timeScale = 0.01f;
    8.     }
    9. }
    If you attach this to a gameobject, and it actually doesn't work - then you should submit a bug report.
     
    Mucossa likes this.