- Home /
Timer that stops at trigger
Hey all, so I want a timer in my game that stops when the player reaches a trigger.
I can do a timer okay but I can't link it up to a trigger any ideas?
Thanks
Comment
Answer by betaFlux · Sep 07, 2014 at 11:04 PM
Something like this should work:
public bool stopTimer {get; set;}
float timer = 5;
void Update()
{
if(timer > 0 && !stopTimer)
{
timer -= Time.deltaTime
}
}
void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag == "player") // requires the tag "player" on your player character
stopTimer = true;
}
Your answer
Follow this Question
Related Questions
Minute Timer Issue 1 Answer
Game Timer help needed 2 Answers
How to make a timer read to the .001 of a second 2 Answers
Timer running down too quickly 1 Answer
how to make a varied countdown timer 1 Answer