- Home /
How do i add and check a timer
in my game, I have a race track model and a car and the race car model has a built in car model so i can animate it and not need AI. but i cannot check the number of laps with the one attached to the track so can somebody please tell me how to set a timer (The animation time is 28 seconds) and how to test to see if it is 28 seconds or less?
I also need to know how to test a collision but ill ask that in a different question
Create a Coroutine (see the docs, very easy) and give it a "yield return new WaitForSeconds(28)"
Answer by Kiwasi · Aug 11, 2014 at 03:15 AM
Coroutines work well for this
For a more general system implement a custom timer
private float timer = 0;
void Update () {
timer += Time.deltaTime;
// To reset the timer
timer = 0;
// To check against the timer
if(timer > 28){
// Do something
}
}
It's C#. Just do it as
private var timer:float = 0;
function Update () {
timer += Time.deltaTime;
// To check against the timer
if(timer > 28){
// Do something
// To reset the timer
timer = 0;
}
}
for JS
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Unity3D Timer. 1 Answer
Set timer to a specific time. 1 Answer
Creating a timer for combat (C#) 1 Answer
My timer freezes everytime I leave the scene and come back. 1 Answer