markus
markus

Reputation: 485

LoadLevelAdditive and UnloadLevel

i've a question about UnloadLevel and LoadLevelAdditive

e.g i've the following Scenes: - level1 - level2 - loadingscene

when level1 is done, i use Application.LoadLevelAdditive(loadingscene); to display the loadingscene and the level1 scene! after the loading scene animation is complete, i want to display level2 instead of level1 but keep the loadingscene. after the 2nd loading animation in loadingscene i want to remove loadingscene.

now i want to know if the following steps are correct to do so

if (level1done)
{
Application.LoadLevelAdditive(loadingscene)
}

play the loading animation

if(loadinganimationdone)
{
Application.UnloadLevel(level1);
Application.LoadLevelAdditive(level2);
}

play the 2nd loading animation

if(2ndloadinganimationdone)
{
Application.UnloadLevel(loadingscene);
}

play the game with only loaded scene level2!

thanks

Upvotes: 2

Views: 1808

Answers (1)

Nika Kasradze
Nika Kasradze

Reputation: 3019

Your logic is correct. However, for a bit faster transitions I'd use LoadLevelAdditiveAsync.

LoadLevelAdditiveAsync (and LoadLevelAsync) method loads the level in a background thread. What you'd need is to set allowSceneActivation of the AsyncOperation to false - do not start level when the loading is done (allowSceneActivation is true by default). After you are done with animations set allowSceneActivation to true. If the level is ready it will start immediately (instead of starting to load the level like you have now).

But this approach has a minor flaw - Unity 5.3 has a separate class for handling level loading - SceneManager. So if you ever need to update your game you should probably check it out.

Upvotes: 2

Related Questions