I’ve tried to implement a timer that should count 10 seconds.
Since this approach crashes it does not seem to be a good implementation. I don’t know why though, because it shouldn’t initiate an infinite loop or anything, should it?
Is there a better alternative?
var startTime: float;
function Update () {
if (a particular button is pressed)
{
startTime = Time.time;
fn_Timer();
}
}
function fn_Timer ()
{
var currentTime = Time.time;
var elapsedTime = currentTime - startTime;
if ( elapsedTime > 10 ) {
// Do other stuff after timer has ended
}
else {
// Call: Timer again
fn_Timer();
}
}