- Home /
Question by
johnmadden1989 · Aug 26, 2014 at 09:01 PM ·
c#timepausetime.timescaleseconds
Pause game while GUI instructions displayed?
Hi!
I have a script attached to my GUITexture that appears a few seconds into my game, and disappears again in 5 seconds.
I was wondering if there is a way to pause the game while this GUI is displayed? It would make the game run a whole lot better.
Thanks in advance.
John
public class TestScript : MonoBehaviour {
private GUITexture myGUITexture;
[SerializeField]
private float delaySeconds = 1.0f;
[SerializeField]
private float showForSeconds = 1.0f;
void Awake() {
myGUITexture = GetComponent<GUITexture>();
}
void Start() {
ShowImage();
}
public void ShowImage() {
StartCoroutine(ShowImageTimed(delaySeconds, showForSeconds));
}
IEnumerator ShowImageTimed(float startDelaySeconds, float showForSeconds) {
Debug.Log("In coroutine.");
yield return new WaitForSeconds(startDelaySeconds);
Debug.Log("Enabled texture.");
myGUITexture.enabled = true;
yield return new WaitForSeconds(showForSeconds);
Debug.Log("Disabling texture.");
myGUITexture.enabled = false;
}
}
Comment
Answer by TheFish657 · Nov 05, 2016 at 11:10 AM
Very late reply but, for future reference, set Time.timeScale to 0 in your coroutine