Exemple #1
0
        void OnSceneLoaded(UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode)
        {
            if (mode != UnityEngine.SceneManagement.LoadSceneMode.Single)
            {
                return;
            }
#else
        void OnLevelWasLoaded()
        {
#endif
            PlayerController player = GetComponent <PlayerController>();
            if (player != null)
            {
                TeleportTo(player.gameObject, TargetTeleporterName);
                player.PhyCtrl.TeleportTo(player.transform.position);
                Destroy(this);
            }
        }

        void Update()
        {
            m_isActivationKeyPressed = m_isActivationKeyPressed && Input.GetKey(ActivationKey) || Input.GetKeyDown(ActivationKey) && Time.timeSinceLevelLoad > 0.5f;
        }

        void TeleportTo(GameObject srcObj, string dstObjName)
        {
            GameObject targetTeleport = GameObject.Find(dstObjName);

            if (targetTeleport == null)
            {
                Debug.LogWarning(" Teleport destination not found: " + dstObjName);
            }
            else
            {
                if (LinkWithTarget)
                {
                    TeleporterBehaviour teleporterBhv = targetTeleport.GetComponent <TeleporterBehaviour>();
                    if (teleporterBhv)
                    {
                        teleporterBhv.TargetSceneName      = m_savedSceneName;
                        teleporterBhv.TargetTeleporterName = m_teleporterName;
                    }
                }
                Vector3 targetPos = targetTeleport.transform.position;
                targetPos.z = transform.position.z;
                srcObj.transform.position = targetPos;
            }
        }
Exemple #2
0
        void DoTeleport(GameObject obj)
        {
#if UNITY_5_3
            if (string.IsNullOrEmpty(TargetSceneName) || TargetSceneName == UnityEngine.SceneManagement.SceneManager.GetActiveScene().name)
#else
            if (string.IsNullOrEmpty(TargetSceneName) || TargetSceneName == Application.loadedLevelName)
#endif
            {
                TeleportTo(obj, TargetTeleporterName);
            }
            else
            {
                TeleporterBehaviour teleportComp = obj.AddComponent <TeleporterBehaviour>();
                teleportComp.TargetTeleporterName = TargetTeleporterName;
                teleportComp.SetTeleporterName(this.name);
#if UNITY_5_3
                UnityEngine.SceneManagement.SceneManager.LoadScene(TargetSceneName);
#else
                Application.LoadLevel(TargetSceneName);
#endif
            }
        }
Exemple #3
0
        void TeleportTo(GameObject srcObj, string dstObjName)
        {
            GameObject targetTeleport = GameObject.Find(dstObjName);

            if (targetTeleport == null)
            {
                Debug.LogWarning(" Teleport destination not found: " + dstObjName);
            }
            else
            {
                if (LinkWithTarget)
                {
                    TeleporterBehaviour teleporterBhv = targetTeleport.GetComponent <TeleporterBehaviour>();
                    if (teleporterBhv)
                    {
                        teleporterBhv.TargetSceneName      = m_savedSceneName;
                        teleporterBhv.TargetTeleporterName = m_teleporterName;
                    }
                }
                Vector3 targetPos = targetTeleport.transform.position;
                targetPos.z = transform.position.z;
                srcObj.transform.position = targetPos;
            }
        }