- Home /
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?
Answer by Lovrenc · Nov 28, 2013 at 08:41 PM
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
Please click on the link i provided in the answer and read about debugging there.
Your answer
Follow this Question
Related Questions
How to finish my else if statement? 2 Answers
Problems with if statements 2 Answers
If \ Else how does the program reads it? 2 Answers
Need help with multiple if statements. 3 Answers
How stop a piece of code from running if the conditions are no more met. 1 Answer