IEnumerator LoadAsy(FadingCurtain TriggerLoad) { TriggerLoad.gameObject.SetActive(true); if (AlreadyLoading) { yield break; } AlreadyLoading = true; //Begin to load the Scene you specify AsyncOperation asyncOperation; if (SceneToLoad != "") { asyncOperation = SceneManager.LoadSceneAsync(SceneToLoad); } else { yield break; } //Don't let the Scene activate until you allow it to asyncOperation.allowSceneActivation = false; while (!asyncOperation.isDone) { print(asyncOperation.progress); // Check if the load has finished if (asyncOperation.progress >= 0.9f) { yield return(new WaitUntil(() => TriggerLoad.CurtainIsBlack)); asyncOperation.allowSceneActivation = true; } yield return(null); } }
public void LoadSceneOnBackground(FadingCurtain TriggerLoad) { StartCoroutine(LoadAsy(TriggerLoad)); }