UI にこれらが必要である。

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

コード
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
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() をコールする必要がある。