- Home /
Question by
the_cokaroach · Dec 07, 2014 at 10:18 PM ·
pausestartfixedupdatetimescale
Pause game on Start doesn't quite work
Trying to pause a game as it starts to wait for some user interaction on the GUI.
Using time.TimeScale = 0.0f; in the Start() function. However it still processes the FixedUpdate() function once.
Using the logs I can clearly show the timescale is altered before the fixed update runs but yet it still runs once.
using UnityEngine;
using System.Collections;
public class TestPause : MonoBehaviour {
void Start () {
Time.timeScale = 0.0f;
Debug.Log("Paused");
}
void FixedUpdate () {
Debug.Log("Updated");
}
}
What am I doing wrong?
Comment
It's could be a safeguard built-in to unity.
Coroutine's still run when the timeScale is 0, so make sure you know how to unpause the game.
Answer by ahmedbenlakhdhar · Dec 07, 2014 at 10:24 PM
Try this script, and change isPaused
value to true
when the user finish its interaction on the GUI:
using UnityEngine;
using System.Collections;
public class TestPause : MonoBehaviour {
bool isPaused;
void Start () {
Time.timeScale = 0.0f;
isPaused = true;
Debug.Log("Paused");
}
void FixedUpdate () {
if(!isPaused){
Debug.Log("Updated");
}
}
}