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!
1 Answer
1
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.
Please convert this to comment, because it's not answer. If you assigned a Weapon in the inspector, then it is not possible for it to be null, unless you assigned null to it somewhere else. Assigned field in component should look like this: ![alt text][1] TestMiniGun is a name of simple Cube with MiniGun script attached. [1]: /storage/temp/15130-playerscript.png
– ArkaneX