x


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!

more ▼

asked Jun 13 '12 at 10:25 PM

Bruno Fludzinski gravatar image

Bruno Fludzinski
104 8 21 28

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
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.

more ▼

answered Jun 13 '12 at 10:35 PM

Wisearn gravatar image

Wisearn
116 2 3 3

thank you that works!

Jun 15 '12 at 10:32 PM Bruno Fludzinski
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x90
x54
x11

asked: Jun 13 '12 at 10:25 PM

Seen: 386 times

Last Updated: Jun 15 '12 at 10:32 PM