Hi,
I have written a script to jump from one level to the next, thinking that I could set it using the inspector to override the variable I set at the start of the script, but the script keeps using the preset variable in the script, rather than what I write in the Inspector. Here’s my code:
var levelToLoad = "Level_02";
function Start(){
}
function Update () {
}
function OnTriggerEnter() {
transform.parent.gameObject.audio.Play();
yield WaitForSeconds(3.0);
Application.LoadLevel(levelToLoad); // Will load Level specified in the inspector view for this game object
}
In the Inspector, I write “Level_03”, but it still goes to Level_02.
All the levels are in the Build Settings, and the same thing happens whether I use the Level names, or the Build index numbers.
Any advice?
B
Actually i don't see a problem with the script itself. However there might be a problem that the gameobject from the previous scene is still there because you used DontDestroyOnLoad or something like that. Since you have a seperate instance of this script in each scene, you could try to rename the gameobject thescript is attached to to the level name. Then add this line at the beginning of your OnTriggerEnter function: Debug.Log("End of level: " + gameObject.name + " Loading new level: " + levelToLoad); Try it and tell us what happens.
– Bunny83