Question by
Vaell · Apr 18, 2017 at 02:55 PM ·
timertimer countdown
I want to stop timer when "time left" reach to zero. Any ideas ?
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class CountDown : MonoBehaviour
{ public float timeLeft = 10;
public Text text;
public GameObject resultsPanel;
public GameObject[] panels;
private int numberOfCorrectAnswers;
public Text resultsText;
void Update()
{
timeLeft -= Time.deltaTime;
text.text = "Time Left:" + Mathf.Round(timeLeft);
if (timeLeft < 0)
{
foreach (GameObject p in panels)
{
p.SetActive(false);
}
resultsPanel.SetActive(true);
displayResults();
}
}
Comment
Best Answer
Answer by Cuttlas-U · Apr 18, 2017 at 04:00 PM
hi; change it to this :
if (timeLeft >= 0)
timeLeft -= Time.deltaTime;
Hey ,that worked, thanks! Also want to stop timer at that number when "resultsPanel.SetActive" part gets true. I mean when every game object gets false, if there is time left , I want to stop timer at that point. Just tried some but did not worked...
hi again; create a boolian first;
public bool TimerWork = true;
then after " resultsPanel.SetActive(true);" write this :
TimerWork = false;
then change this lane like this :
if (timeLeft >= 0 && TimerWork == true)
timeLeft -= Time.deltaTime;