not loading levels properly

ok so I’m relatively new to Unity3D. I made a worminator game (from the tornado twins tutorial) and I’ve fixed a lot of bugs I had with it before (like spawning halfway off the map when you die), but one still eludes me and it doesn’t seem to be a coding problem (although it may be, but I figured it’d be best to post this here).

basically, I have a splash page, a first level, and a second level. Going from the splash page, I can load up level one just fine and play through it just fine. Then when I beat it it’s suppose to load up level 2, but when it does it bugs out and says this and that doesn’t have an object, something about there not being a reference. I can’t seem to figure out why this is, because if I go to play the scene on its own it works 100% fine.

Can anyone figure this out maybe?

Also, just tried something out (making it so when I beat the second level it goes to splash page). When I did it went and worked but when I tried to reload level 1 it bugged out like on the first load of level 2. Could it have something to do with my script not loading correctly? What I mean is, now that I’ve set the below variable next_level to 0 (the index of my splash screen) in the hierarchy panel, when I beat level 1 it loads up level 2 then instantly loads the splash screen, if I try to load level one after that it bugs out like level 2 does and instantly loads level 2 and then the splash screen.

static var turret_number = 1;
var next_level = 2;

function Update(){

	if(turret_number == 0){
	
		Application.LoadLevel(next_level);
	
	}

}

Edit: oh yeah and none of my scripts have DontDestroyOnLoad on them if that helps any.

Make sure all your scenes are included in the build settings in the correct order. You can see the index numbers also in there.
In the script you posted you go from scene 0 to scene 2.
Can you also post the exact error message. It usualy tells you where to look.

well I figured it out. idk why it was but for some reason it didn’t reset the var turret_number back up from 0 when it loaded a new scene (even tho I didn’t have DontDestroyOnLoad() active in the script). By putting in turret_number = 1; before Application.LoadLeve(); it fixed the problem.

but yeah my build settings were all fine, guess it was just a wierd scripting error.

Perhaps you should put that in the start/awake function so that it gets re-assigned again. :smile: