- Home /
How to stop a Countdown Timer?
The timer doesn't stop when I hit the trigger. I can't figure out whats wrong. Here's my script. Any ideas how I can fix this please? Thanks in advance.
var Seconds:float=59;
var Minutes: float = 0;
var stopTimer : boolean;
function Start() {
stopTimer = true;
}
function Update(){
if(stopTimer){
if(Seconds <= 0){
Seconds = 59;
if(Minutes >= 1){
Minutes--;
}
else{
Minutes = 0;
Seconds = 0;
Application.LoadLevel("test");
GameObject.Find("TimerText").guiText.text = Minutes.ToString("f0") + ":0" + Seconds.ToString("f0");}
}
else{
Seconds -= Time.deltaTime;
}
}
if(Mathf.Round(Seconds) <= 9) {
GameObject.Find("TimerText").guiText.text = Minutes.ToString("f0") + ":0" + Seconds.ToString("f0");
} else {
GameObject.Find("TimerText").guiText.text = Minutes.ToString("f0") + ":" + Seconds.ToString("f0");
}}
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Finish"){
stopTimer = false;
}}
Comment
Answer by YoungDeveloper · Jan 05, 2014 at 04:34 PM
Are you sure the trigger works?
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Finish"){
Debug.Log("works");
stopTimer = false;
}
}
Do you get the message?
Yes, but the countdown is still running when I hit the trigger.
Your answer
Follow this Question
Related Questions
Countdown Timer Help About putting 0's 1 Answer
script countdown 2 Answers
making a timer (00:00) minutes and seconds 10 Answers
Making a timer 1 Answer
Start timer with trigger 1 Answer