- Home /
Teleportation
Hi, I have made a teleportation cube in my game, so when you touch it, it teleports you, using this code:
var destination : Transform;
function OnTriggerEnter(other : Collider) { other.transform.position = destination.position; }
but i want to make it so no matter where i am, if i press a key, i teleport to my destination, thank you!
Answer by Wisearn · Jun 13, 2012 at 10:35 PM
var other : GameObject;
var destination : Transform;
function Update () {
if (Input.GetKey (KeyCode.F5)) {
other.transform.position = destination.position;
}
}
And just assign your player and the destination in the inspector.
http://unity3d.com/support/documentation/ScriptReference/Input.GetKey.html http://unity3d.com/support/documentation/ScriptReference/KeyCode.html
You might want to use GetKeyDown instead... but this should get you started.
Your answer
Follow this Question
Related Questions
teleportation 1 Answer
Help Cannot convert type 'PhotonPlayer' to 'UnityEngine.GameObject' 1 Answer
Issue with Teleporting Object 1 Answer
teleport an object three quarters of its distance with the player after a certain time 2 Answers
teleport destination differs when player hits trigger from different positions 0 Answers