//Transition to the next scene private IEnumerator SceneTransition() { if (m_SceneToLoad < 0) { Debug.Log(gameObject.name + " Has no destination scene set"); yield break; } //Ensure Portal continues to exist until all actions are completed DontDestroyOnLoad(gameObject); SceneFader sceneFade = FindObjectOfType <SceneFader>(); SavingWrapper savingWrapper = FindObjectOfType <SavingWrapper>(); //Get the player controller and disable PlayerController oldPlayerControlComp = GameObject.FindWithTag("Player").GetComponent <PlayerController>(); oldPlayerControlComp.enabled = false; //Fade out the scene yield return(sceneFade.SceneFadeOut(m_FadeOutTime)); //Save game state old scene savingWrapper.Save(); yield return(SceneManager.LoadSceneAsync(m_SceneToLoad)); //Get the player controller and disable PlayerController newPlayerControlComp = GameObject.FindWithTag("Player").GetComponent <PlayerController>(); newPlayerControlComp.enabled = false; //Load game state after new scene is loaded. savingWrapper.Load(); Portal destinationPortal = GetDestinationPortal(); UpdatePlayerPosition(destinationPortal); //Save game state new scene savingWrapper.Save(); yield return(new WaitForSeconds(m_FadeWaitTime)); yield return(sceneFade.SceneFadeIn(m_FadeInTime)); //Enable player control newPlayerControlComp.enabled = true; //Debug.Log("SCENE LOADED"); //Destroy old Portal after all transistions are completed. Destroy(gameObject); }
/// <summary> /// This co-routine loads the last scene. /// </summary> /// <returns></returns> private IEnumerator LoadLastScene() { //Load the last scene from the savefile on start yield return(GetComponent <SavingSystem>().LoadLastScence(m_DefaultSaveFile)); SceneFader fader = FindObjectOfType <SceneFader>(); //Fade out before loading last scene fader.FadeOutImmediately(); //Fade back in yield return(fader.SceneFadeIn(m_FadeInTime)); }