private IEnumerator FirstSceneLoadingLogic() { gameState = GameStates2.loading; yield return(new WaitForSeconds(0.1f)); //Dit is LELIJK! if (!SceneManager.GetSceneByName(newSceneName).isLoaded) { SceneManager.LoadSceneAsync(newSceneName, LoadSceneMode.Additive); while (!SceneManager.GetSceneByName(newSceneName).isLoaded) { yield return(null); } Scene scene = SceneManager.GetSceneByName(newSceneName); SceneManager.SetActiveScene(scene); InstatiateCore(); StartCoroutine(BlackScreenManager.Instance.FadeBlackScreen_Out(BlackScreenManager.Instance.fadeOutTime)); yield return(new WaitForSeconds(BlackScreenManager.Instance.fadeOutTime)); gameState = GameStates2.playing; currentSceneName = newSceneName; } else { Scene scene = SceneManager.GetSceneByName(newSceneName); SceneManager.SetActiveScene(scene); InstatiateCore(); StartCoroutine(BlackScreenManager.Instance.FadeBlackScreen_Out(BlackScreenManager.Instance.fadeOutTime)); yield return(new WaitForSeconds(BlackScreenManager.Instance.fadeOutTime)); gameState = GameStates2.playing; currentSceneName = newSceneName; } }
private IEnumerator ChanceScene(float delayBeforeDeath) { //GameState = loading gameState = GameStates2.loading; //Wait for some time if player dies to Death_Box yield return(new WaitForSeconds(delayBeforeDeath)); //Load blackScreen StartCoroutine(BlackScreenManager.Instance.FadeBlackScreen_In(BlackScreenManager.Instance.fadeInTime)); //Wait for blackScreen fadeInTime yield return(new WaitForSeconds(BlackScreenManager.Instance.fadeInTime)); //Unload current gameplay scene if loaded if (SceneManager.GetSceneByName(currentSceneName).isLoaded) { SceneManager.UnloadSceneAsync(currentSceneName); } //Wait for blackScreen fadeBlackTime yield return(new WaitForSeconds(BlackScreenManager.Instance.fadeBlackTime)); //Load gameplay scene SceneManager.LoadSceneAsync(newSceneName, LoadSceneMode.Additive); //Wait for gameplay scene to be loaded while (!SceneManager.GetSceneByName(newSceneName).isLoaded) { yield return(null); } //1. Set gameplay scene active 2. Unload blackScreen 3. Instatiate Player & Camera 4. Set currentSceneName to newSceneName SceneManager.SetActiveScene(SceneManager.GetSceneByName(newSceneName)); StartCoroutine(BlackScreenManager.Instance.FadeBlackScreen_Out(BlackScreenManager.Instance.fadeOutTime)); InstatiateCore(); currentSceneName = newSceneName; //Wait for blackScreen fadeOutTime yield return(new WaitForSeconds(BlackScreenManager.Instance.fadeOutTime)); //GameState = playing gameState = GameStates2.playing; }