Weird problem with simple boolean and "if" statement [C#]
Hello everyone,
I have a static bool that I toggle between true and false in scriptA. In scriptB I have an if statement where I check if it's true or not. Depending on this I play either coRoutine1 or coRoutine2. coRoutine 2 is the same as coRoutine 1, it's just less fast. The problem is, it's always playing coRoutine1. I did a Debug.Log to check if the boolean was changing correctly and it does. It's like the "if" doesn't check.
Here's the scriptB :
void Update () {
if (COF == cubeToKnock) {
Debug.Log (GlobalVars.allComplete); // works fine
if (GlobalVars.allComplete == false) {
StartCoroutine (outLevel()); //coroutine1, always plays this one no matter what
}
if (GlobalVars.allComplete) {
StartCoroutine (outLevel5()); //coroutine2
}
}
}
If you have an idea, could you help me please ? It's juste so weird ^^'
Thanks.
I rewrote this a little so it's cleaner:
void Update () {
if (COF != cubeTo$$anonymous$$nock)
return;
Debug.Log (GlobalVars.allComplete); // works fine
if (GlobalVars.allComplete) {
StartCoroutine (outLevel5());
}
else {
StartCoroutine (outLevel()); //coroutine2
}
}
Anyways, your code CANNOT start outLevel when allComplete is false. How did you check that?
Thank you for your answer :).
I wasn't able to answer since I didn't have access to the Internet for the past 2 weeks. Anyway I did solve the problem but for the life of me I cannot remember how. Unfortunately I really don't have the time to check it out since school started again. I think I added a private bool somewhere but I'm not sure.
PS : If you really want to know how I did it, let me know and I'll take the time to explain what I did. However I'm a newbie so I doubt this is interesting.