Пример #1
0
        /// <summary>
        /// Load the other scene.
        /// </summary>
        /// <returns></returns>
        private IEnumerator Transition()
        {
            if (sceneToLoad < 0)
            {
                Debug.Log("Scene to load not set.");
                yield break;
            }

            /*
             * Save this portal at the first.
             * Then use this portal to find which portal the
             * player should be teleported to.
             */
            DontDestroyOnLoad(gameObject);

            Fader fader = FindObjectOfType <Fader>();

            yield return(fader.FadeOut(fadeOutTime));

            // Save current level.
            SavingWrapper wrapper = FindObjectOfType <SavingWrapper>();

            wrapper.Save();

            yield return(SceneManager.LoadSceneAsync(sceneToLoad));

            // Load current level.
            wrapper.Load();

            Portal otherPortal = GetOtherPortal();

            UpdatePlayer(otherPortal);
            // Resave player's infomation when changed scene.
            wrapper.Save();

            yield return(new WaitForSeconds(fadeWaitTime));

            yield return(fader.FadeIn(fadeInTime));

            Destroy(gameObject);
        }
Пример #2
0
        private IEnumerator Transition()
        {
            if (sceneToLoad < 0)
            {
                Debug.LogError("Scene to load not set.");
                yield break;
            }

            DontDestroyOnLoad(gameObject);

            Fader            fader            = FindObjectOfType <Fader>();
            SavingWrapper    savingWrapper    = FindObjectOfType <SavingWrapper>();
            PlayerController playerController = GameObject.FindWithTag("Player").GetComponent <PlayerController>();

            playerController.enabled = false;

            yield return(fader.FadeOut(fadeOutTime));

            savingWrapper.Save();

            yield return(SceneManager.LoadSceneAsync(sceneToLoad));

            PlayerController newPlayerController = GameObject.FindWithTag("Player").GetComponent <PlayerController>();

            newPlayerController.enabled = false;

            savingWrapper.Load();

            Portal otherPortal = GetOtherPortal();

            UpdatePlayer(otherPortal);

            savingWrapper.Save();

            yield return(new WaitForSeconds(fadeWaitTime));

            fader.FadeIn(fadeItTime);

            newPlayerController.enabled = true;
            Destroy(gameObject);
        }