I'm trying ot use LoadLevelAsync for the first time, in Unity Pro 4.1.5f1.
The following script in an empty scene, attached to an empty GameObject, causes the Unity editor itself to hang, every time.
Does this happen for other people? What am I doing wrong? This looks OK to me...
using UnityEngine;
using System.Collections;
public class SceneLoader : MonoBehaviour {
string targetScene = "MainGame";
AsyncOperation asyncOp;
IEnumerator Start() {
// Load and wait
asyncOp = Application.LoadLevelAsync(targetScene);
asyncOp.allowSceneActivation = false;
yield return asyncOp;
Debug.Log("Load complete!");
}
void Update () {
if (asyncOp.isDone) {
Debug.LogError("Done Loading");
}
}
void OnGui() {
if (asyncOp != null) {
GUI.Box(new Rect(0, Screen.height - 40, asyncOp.progress * Screen.width, 40), "");
}
}
}
It seems without the `asyncOp.allowSceneActivation = false;` line, it works. I wanted to start a fade transition on load complete, so I don't want it to swap scenes for me.
↧