- Home /
Where is this (-1) coming from in my change level script?
I have a script that changes from Level 1-1 to level 1-2 just fine.
function OnTriggerEnter (other : Collider){
if(other.gameObject.tag == "Player"){
Application.LoadLevel("1-2");
}
}
But I have a script that is exactly the same but to loads level 1-3 instead.
function OnTriggerEnter (other : Collider){
if(other.gameObject.tag == "Player"){
Application.LoadLevel("1-3");
}
}
But when I enter the trigger I get this error:
Level '1-3' (-1) couldn't be loaded because it has not been added to the build settings. To add a level to the build settings use the menu File->Build Settings... UnityEngine.Application:LoadLevel(String) Level 1-3:OnTriggerEnter(Collider) (at Assets/Scripts/NextLevels/Level 1-3.js:5)
Where is the (-1) Coming from? I have level 1-3 in the Scenes in build menu. The same thing was happening when I was trying to go from 1-1 to 1-2 but it just stopped randomly.
Thanks in advance for any help.
Is Level 1-3's checkbox ticked in the Build Settings window? Sorry, that's all I can think of.
Answer by fafase · Apr 25, 2015 at 05:38 PM
The -1 comes is probably the internal return value for the LoadLevel method indicating an error. It is classic in C++ to have a negative value for fail (in any language actually).
In your case, it indicates what is said after, the scene is missing from the build. Open up the Build setting, I think it is in File, then drag and drop the missing scene there.