I have the trouble with function Application.loadedLevelName.
I want to realize a loading progress bar and have divided the main scene on several to load them one after another.
function Start () {
if (Application.loadedLevelName == "Loader") {
Application.LoadLevelAdditive ("Models");
}
}
function Update()
{
print("loadedLevelName = "+ Application.loadedLevelName);
}
The scene “Models” has loaded but all time the console prints - “Loader”.
May be I’m doing wrong?
If I have correctly understood, the functions Application.loadedLevel and Application.loadedLevelName do not work with LoadLevelAdditive. They work only for LoadLevel. If yes then pls add it in ScriptReference!
How can I check the name of level loaded with LoadLevelAdditive?
@magic3d: You are correct with your assessment. LoadLevel() is the only method that affects Application.loadedLevel and Application.loadedLevelName. There is no way to check for the name of a level loaded with LoadLevelAdditive, however, since it loads by the next frame, you can store the name of the level you are loading in some buffer for use the next frame.
I’ve logged a documentation bug to be clearer about this in the scripting documentation.
I usually do a GameObject.Find() call to see if one of the objects from the loaded scene is present before executing any further code on the added scene. Works well for me but I agree, this should be addressed by the Unity dev team.