public IEnumerator ActivateLoadingAnimationAndLoadNextScene(int levelIndex) { LoadingManager loadingManager = FindObjectOfType <LoadingManager>(); bool animationComplete = false; loadingManager.Show(() => animationComplete = true); AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(levelIndex); asyncLoad.allowSceneActivation = false; // Wait until the asynchronous scene fully loads while (asyncLoad.progress < 0.9f || !animationComplete) { yield return(null); } asyncLoad.allowSceneActivation = true; OnSceneChanged.Invoke(); if (loadingManager != null) { loadingManager.Hide(); } }