Unity・シーン非同期ローダー

UI にこれらが必要する。

そしてUIでこのようになる。

コード

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using static System.Net.Mime.MediaTypeNames;

public class LoadManager : MonoBehaviour
{
    [Header("背景")] public GameObject BackGround;
    [Header("スライダー")] public Slider slider;
    [Header("テキスト")] public TextMeshProUGUI text;

    public void LoadNextLevel()
    {
        StartCoroutine(LoadLevel());
    }

    IEnumerator LoadLevel()
    {
        // operation = このシーンの番号 + 1
        AsyncOperation operation = SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex + 1);

        while(!operation.isDone)
        {
            slider.value = operation.progress; // スライダー進度を設定

            text.text = operation.progress * 100 + "%"; // テキストで進度を表示する

            yield return null;
        }
    }
}

非同期ローダーをしたい時に LoadNextLevel() をコールする必要がある。