Search Unity

Teleportation

Discussion in 'Scripting' started by Paykoman, Mar 5, 2015.

  1. Paykoman

    Paykoman

    Joined:
    Jun 26, 2014
    Posts:
    500
    Hi guys wt i want to know is i eve this next script attached to a game object so when i click it i load a new scene, everything works fine but i hv one issue and 1 question...

    1- Right now i can click for all over the place and i get teleported, so wt i need some help is to only work when inside a certain range.

    2- how i can teleport inside the scene i select but to a specific Vector3 position? For example if im in town and i teleport to inside a dungeon i go to begining, thats right, but if i port back right now it goes to start point of town, and i want it to return to the teleport position in town of dungeon entrance.

    Appreciate any help
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class EnterDungeon : MonoBehaviour
    5. {
    6.  
    7.     // Use this for initialization
    8.     void Start ()
    9.     {
    10.    
    11.     }
    12.    
    13.     // Update is called once per frame
    14.     void Update ()
    15.     {
    16.         if(Input.GetMouseButton(1))
    17.         {
    18.             Application.LoadLevel("Dungeon");
    19.         }
    20.     }
    21. }
    22.  
     
  2. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    994
    For your second question, Use DontDestroyOnLoad (http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html) to keep an object in your dungeon at the teleport's location and when you go back to your dungeon, scan if such an object exist. If it does, move there.

    Or store your teleport's position in a static variable and use that.