Skip to content

How to Create an Asynchronous Scene Loader in Unity

add Using UnityEngine.SceneManagement

public class SceneLoader : MonoBehaviour
{
public string sceneName;

public void LoadScene()
{

StartCoroutine(LoadAsynchronousOperation());

}

IEnumerator LoadAsynchronousOperation()

{

AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName);

// Wait until the asynchronous scene fully loads

while (!asyncLoad.isDone)

{

yield return null;

}

}

}

Reference:

https://docs.unity3d.com/2019.4/Documentation/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html

Leave a Reply

Your email address will not be published. Required fields are marked *