- Home /
Time.timescale=0 not working when the timeleft "countdown" reduce to 0
the game should stop if the timeleft=0 on update. Can someone tell me why and fix the scripts ThankYOu
using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement;
public class FailedDialoue : MonoBehaviour { [SerializeField] private float timeLeft; [SerializeField] private Text text;
[SerializeField]
private int levelToLoad;
[SerializeField]
private GameObject dBox;
[SerializeField]
private Text dText;
public bool dialogActive;
public string[] dialogLines;
public int currentLine;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
timeLeft -= Time.deltaTime;
text.text = "Time Left:" + Mathf.Round(timeLeft);
if (timeLeft < 0)
{
Time.timeScale = 0.0f;
dBox.SetActive(true);
dialogActive = true;
}
if (dialogActive && Input.GetKeyDown(KeyCode.Space))
{
//dBox.SetActive (false);
//dialogActive = false;
currentLine++;
}
if (currentLine >= dialogLines.Length)
{
dBox.SetActive(false);
dialogActive = false;
SceneManager.LoadScene(levelToLoad);
currentLine = 0;
}
dText.text = dialogLines[currentLine];
}
}
You need to be more specific about what is happening and what's not happening. If I abstract the relevant parts of the script (timeleft countdown & setting time.timescale) it works fine. So.. what exactly isn't happening that you expect to happen? what have you tried? have you tried writing timeleft to the debug window to make sure it's behaving like you assume it is?
have you double checked whether time.timescale is actually setting to zero at runtime?
Are you sure the script is attached to a gameobject and it is enabled?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Problem with Time.timeScale 0 Answers
Timer manipulation with timescale not working correctly 2 Answers
Rotate problem. 1 Answer