Hey guys i have a question aboute this little script
function Start () {
// Load the level named "SGC Alpha V.01.0".
var async : AsyncOperation = Application.LoadLevelAsync ("SGC Alpha V.01.0");
yield async;
Debug.Log ("Loading complete");
}
function OnTriggerEnter ()
//When i enter the trigger it should load the preloaded level right?//
{
Application.LoadLevel ("SGC Alpha V.01.0");
}
//Can in be so that when unity is finished loading the new preloaden sene that it deleted the old one ?//
Assuming your question is “Will Unity delete the previous scene when it loads the new one?”, yes, it will. If you want to keep the previous level loaded (so the new one is added to the scene), use Application.LoadLevelAdditiveAsync("SGC Alpha V01.0"). Please note that additive and async level loading requires a Unity Pro license.
Or if your question is when will Unity load the level, the answer is in the documentation: LoadLevelAsync will load the level and apply it immediately after loading. I believe that currently it’s impossible to preload a level but only switch to i in a later moment. If you were to go the advanced (but free) way, you could:
Store your levels in a file
Load this file sometime in the game
Destroy all objects in the current scene
Apply the loaded data to the scene, instantiating the new level
This is rather advanced because you’re basically creating a level system from scratch.