- Home /
freeze the scene
Hi guys.. I am trying to freeze the scene when my player hits certain objects and a gui window pops up. I tried to use a coroutine to do that but it seems like i don't get the result I want. Any help?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Gui2 : MonoBehaviour {
[Serializefield] private GameObject customText;
IEnumerator OnTriggerEnter(Collider other)
{
if(other.CompareTag("Player"))
{
customText.SetActive (true);
Time.timeScale = 0.0f;
yield return new WaitForSeconds(3.5f);
customText.SetActive(false);
Time.timeScale= 1.0f;
}
}
}
I'm not certain, but I assume that WaitForSeconds uses Time.deltaTime or something similar, so when you set the timeScale to 0, you're also freezing the coroutine (This is all just an educated guess).
A quick look at the documentation and it seems you may want to use WaitForSecondsRealtime.
Hope i'm right and that works out for you!
Since this is absolutely correct, you might want to add that as an answer rather than a comment so other people can find it too.
Excellent, then we both learnt something today!
Answer by GamerJoHo · Jul 06, 2017 at 04:16 PM
I'm not certain, but I assume that WaitForSeconds uses Time.deltaTime or something similar, so when you set the timeScale to 0, you're also freezing the coroutine (This is all just an educated guess).
A quick look at the documentation and it seems you may want to use WaitForSecondsRealtime.
Hope i'm right and that works out for you!