If I have a scene(named ‘Level1.unity’), saved within a subfolder of assets(named ‘NightWorld’), and added it to the Build Settings(listed as ‘NightWorld/Level1.unity’), how can I load that using Application.LoadLevel()?
I tried Application.LoadLevel(“NightWorld/Level1.unity”), but got ‘Level couldn’t be loaded because it has not been added to the build settings.’
Does anyone know why it isn’t loading the level even though it clearly shows it in the Build Settings? Do I not just use folder-name/scene-name?
Heu nope… just Application.LoadLevel(“Level1”);
So long as you include the scenes in your build via the Build Settings, you can do the following to load your scene:
public static void LoadLevel(string name, int sublevel)
{
Application.LoadLevel(string.Format("{0}_{1}", name, sublevel));
}
You could then call it like so:
LoadLevel("NightWorld", 1);
And it would load the level called “NightWorld_1” if it exists. Not sure if that would throw an exception if it ever fails, but it might be a good idea to surround your call to the function with a try / catch and handle it appropriately with UI messing or something.
EDIT: For more clarification, the way that the level is included in the game is by its name, not its full path. Let’s say your level is stored like so: “Levels/NightWord/Level1.unity”, when you go to load the level in Unity, all you need to type is “Level1”. Unity removes the full path of the level. (This is both a blessing and a curse, I’m afraid.)