[closed] problem with invokerepeating and public variable

hi,

i have this code:


public var state:int;

private var startTimer = false;

private var time = 4;

function Update()

{


if (state == 6)

{

if (!startTimer)

{

    InvokeRepeating("Timer", 0, 1);

    startTimer = true;

}

}


function Timer()

{

if (--time <= 0)

{

     Debug.Log("i'm here");

     state = 7;

     CancelInvoke("Timer");

}

}


he point is… the invokeworks ok. it make a countdown from 4 to 0 and print “i’m here” and cancelInvoke.
But state continue = 6

what i’m doing wrong?
Thanks

Try this :

// JavaScript Document
public var state : int;
private var startTimer : boolean = false;
private var time : int = 4;

function Update() {

    if (state == 6) {
        if (!startTimer) {
            InvokeRepeating("Timer", 1, 1);
            startTimer = true;
        }
    }
}

function Timer() {

    time = time - 1;

    if (time <= 0) {
 
        Debug.Log("i'm here");
        state = 7;
        CancelInvoke("Timer");
    }
}