Unable to change Time.timeScale

I was trying to make a pause menu, which seemed simple enough. However, nomatter what I change Time.timeScale to it instantly reverts it back to 1…
after a while I tried manually changing it under Edit → Project Settings → Time, but it automatically reverts it back to 1 there too…

Note:
I loaded the script into a different project and it worked perfectly. So it may be an issue with my project settings? They’re all just the defaults as far as I’m aware though…

using UnityEngine;
using System.Collections;


public class PauseMenu : MonoBehaviour {

    bool paused = false;

    void Update ()
    {
        if ( Input.GetKeyDown( KeyCode.Escape ) )
        {
            Pause();
        }
        Debug.Log ( Time.timeScale );

    }

    void Pause()
    {
        paused = !paused;
      
        Time.timeScale = 1.0f - Time.timeScale;
    }
  
    void OnGUI()
    {
        if ( paused )
        {
            var rect = new Rect( 10, 10, 100, 30 );
            rect.center = new Vector2( Screen.width/2, Screen.height/2 - 35 );
        
            if ( GUI.Button( rect, "Return to Game" ) )
            {
                Pause();
            }
          
            rect.center = new Vector2( rect.center.x, rect.center.y + 35 );
          
            if ( GUI.Button( rect, "Quit to Main Menu" ) )
            {
                // unpause / reset timescale before loading new scene
                Pause();
                Application.LoadLevel( "MainMenu" );
            }
        }
    }
}

Time.timeScale = 1f - Time.timeScale;

In your script, you’re missing a semicolon after your line. It needs to be there.


Also:

  • You can stop the execution of FixedUpdate() with Time.timescale=0
  • You cannot stop the execution of Update()/LateUpdate(), unless you disable the script.

You may be changing Time.timeScale value in another script.