if else statement doesnt work

Hello, my endGame function doesn’t work properly,
if(myCounter > 3){ chooses the wrong level to load.
Does anyone know why that is the case?

var myCounter : float;

function Update () {
    Debug.Log (myCounter);
}


function Start () {
	endGame ();
}


function OnTriggerEnter ( other : Collider) {
    myCounter += 1.0;
}

function endGame (){    
    yield WaitForSeconds (15); 
   	if(myCounter > 3){        	
   	    Application.LoadLevel ("Level_01");
    } else  {
   	    Application.LoadLevel ("GameOverScreen");
    }
}

Please format the code before posting on UAnswers. I'll do it this time.

–

"chooses the wrong level to load". So which level does it load?

–

1 Answer

1

Your myCounter variable probably does not have the value you anticipate. Debug it in monobehaviour and see what is going on.

i have a debug in the function update and it counts as it should but even if after the 15 seconds it loads the gameoverscreen

–

Put the breakpoint in the if statement.

–

could you please explain what you mean?

–

Please click on the link i provided in the answer and read about debugging there.

–

all levels have been added to the build settings yeah?

–