Complicated level change problem
So I have a script that uses a variety of variables to figure out what scene should be switched to in Unity. However, I am having a problem:
if (houseProgress == 0 && inHouse == true) {
houseProgress += 1;
stopChecking = false;
GameControl.control.Save ();
SceneManager.LoadScene ("Scene1");
}
if (houseProgress == 1 && inHouse == true){
houseProgress += 1;
GameControl.control.Save ();
SceneManager.LoadScene ("Scene2");
}
As you can see, there are two variables that determine what scene unity should switch to. First off, the game checks how much "house progress" the player has gone through to determine what scene they should go to. After that, it also checks to determine if they are in the house scene (basically, there's a bit of code that I'm not showing that determines what the boolean is based on the scene name; if the scene name is "house," the boolean is true, and if the scene name is anything else, it's false).
My problem arises from the following: when the code is executed with the houseProgress variable being 0 and the inHouse variable being true, the scene that shows up is Scene2. Now, I do know that Scene1 is in fact loaded, but for only a split second. I know this to be true because I put a debug in the code for the first scene.
Strangely enough, it doesn't even stop with loading Scene2. You see, I have more scenes (Scene3, Scene4, etc.) that are set up, but they aren't in the build settings yet. However, the code attempts to load each of these levels until the last one I indicate is attempted. Basically, despite my houseProgress variable being 0, the code runs right through all of the scenes until the last one I indicate.
So what is happening here!? I have a strong feeling it is because I used "=" incorrectly somewhere because this tends to be the case for me with these kinds of things. However, I am uncertain, so I am hoping you guys could help me out!
Answer by e4lime · May 10, 2016 at 04:18 PM
You are increasing houseProgress inside the first statement so when it checks the second if condition it sees that houseProgress is 1.
Change the ifs to if else, or use a switch or abort with a "return;" just after you call SceneManagar.LoadScene()