Unity/Csharp/画面遷移/非同期
提供: 初心者エンジニアの簡易メモ
public class SampleAsyncScene : MonoBehaviour { [SerializeField] Button button; void Start() { button.onClick.AddListener(OnClickButton); } void OnClickButton() { StartCoroutine(LoadSceneAsync("SubScene")); } IEnumerator LoadSceneAsync(string sceneName) { AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName); Debug.Log("asyncLoad.progress=" + asyncLoad.progress); asyncLoad.allowSceneActivation = false; // asyncLoad.progressが0.9でisDoneがfalse // if (asyncLoad.progress >= 0.9f) while (!asyncLoad.isDone) { Debug.Log("asyncLoad.progress=" + asyncLoad.progress); asyncLoad.allowSceneActivation = true; yield return null; } } }