Cooldown Timer Help!

Ive got my timer working in a sloppy way… I was trying to do something like this:

var stinkcool = false;
var stinktimer = 19;
function stinkcooldowntime () {
stinkcool = true;
if (stinkcool == true && stinktimer > 1) {
stinktimer = stinktimer -1;
}
if (stinktimer == 0) {
stinkcool =false;
}

but it doesnt keep subtracting, it stops…
any help??

It’s that when stinktimer gets the integer value ‘1’, it gets stuck. Both if statements don’t take it because one of them requires stinktimer to be more than 1 and other requires 0. I’d recommend “for” or “while” though.

Anyway, your code should be like this :

var stinkcool = false;
var stinktimer = 19;
function stinkcooldowntime () {
stinkcool = true;
if (stinkcool == true && stinktimer >= 0) {
stinktimer = stinktimer -1;
}
if (stinktimer == 0) {
stinkcool =false;
}

With this. When it reaches 0, it will stop substracting and go to second if statement. Good luck.

If you don’t want this in your Update function, then you could do:

function StinkCooldownTime() {
    stinkCool = true;
    var timer : float = stinkTimer;
    while(timer > 0)
    {
        timer -= Time.deltaTime; //time between this frame and the last frame
        yield WaitForEndOfFrame(); //one of a few YieldInstructions that come in handy
    }
    stinkCool = false;
}