Skip to main content
added 225 characters in body
Source Link

You can load the next scene asynchronously using SceneManager.LoadSceneAsync() using coroutines. You can use this strategy on a splash / loading screen if you're wanting to see it load before showing the menu.

using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Example : MonoBehaviour
{
    void Update()
    {
        // Press the space key to start coroutine
        if (Input.GetKeyDown(KeyCode.Space))
        {
            // Use a coroutine to load the Scene in the background
            StartCoroutine(LoadYourAsyncScene());
        }
    }

    IEnumerator LoadYourAsyncScene()
    {

        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("Scene2");

        // yield to other processes until the scene is loaded
        while (!asyncLoad.isDone)
        {
            yield return null;
        }

        // Do something here like enabling the play button or closing the splash/loading screen
    }
}

Code example from: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html

EDIT: As has been indicated in the comments, if you want to control when the scene loads, you can use the allowSceneActivation flag on the above AsyncOperation object. asyncLoad.allowSceneActivation = false; When you want it to load the next scene: asyncLoad.allowSceneActivation = true;

You can load the next scene asynchronously using SceneManager.LoadSceneAsync() using coroutines. You can use this strategy on a splash / loading screen if you're wanting to see it load before showing the menu.

using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Example : MonoBehaviour
{
    void Update()
    {
        // Press the space key to start coroutine
        if (Input.GetKeyDown(KeyCode.Space))
        {
            // Use a coroutine to load the Scene in the background
            StartCoroutine(LoadYourAsyncScene());
        }
    }

    IEnumerator LoadYourAsyncScene()
    {

        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("Scene2");

        // yield to other processes until the scene is loaded
        while (!asyncLoad.isDone)
        {
            yield return null;
        }

        // Do something here like enabling the play button or closing the splash/loading screen
    }
}

Code example from: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html

You can load the next scene asynchronously using SceneManager.LoadSceneAsync() using coroutines. You can use this strategy on a splash / loading screen if you're wanting to see it load before showing the menu.

using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Example : MonoBehaviour
{
    void Update()
    {
        // Press the space key to start coroutine
        if (Input.GetKeyDown(KeyCode.Space))
        {
            // Use a coroutine to load the Scene in the background
            StartCoroutine(LoadYourAsyncScene());
        }
    }

    IEnumerator LoadYourAsyncScene()
    {

        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("Scene2");

        // yield to other processes until the scene is loaded
        while (!asyncLoad.isDone)
        {
            yield return null;
        }

        // Do something here like enabling the play button or closing the splash/loading screen
    }
}

Code example from: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html

EDIT: As has been indicated in the comments, if you want to control when the scene loads, you can use the allowSceneActivation flag on the above AsyncOperation object. asyncLoad.allowSceneActivation = false; When you want it to load the next scene: asyncLoad.allowSceneActivation = true;

Source Link

You can load the next scene asynchronously using SceneManager.LoadSceneAsync() using coroutines. You can use this strategy on a splash / loading screen if you're wanting to see it load before showing the menu.

using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Example : MonoBehaviour
{
    void Update()
    {
        // Press the space key to start coroutine
        if (Input.GetKeyDown(KeyCode.Space))
        {
            // Use a coroutine to load the Scene in the background
            StartCoroutine(LoadYourAsyncScene());
        }
    }

    IEnumerator LoadYourAsyncScene()
    {

        AsyncOperation asyncLoad = SceneManager.LoadSceneAsync("Scene2");

        // yield to other processes until the scene is loaded
        while (!asyncLoad.isDone)
        {
            yield return null;
        }

        // Do something here like enabling the play button or closing the splash/loading screen
    }
}

Code example from: https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadSceneAsync.html