Put this on your player (or any other object) then drag some other object from your hierarchy onto the "teleport" slot (this will be the end-location after teleporting , I'd create an empty game object to use as the teleport) ; after that, push play, hit the "T" key, and poof... magic.
var teleport : Transform ; //<--Drag object from Hierarchy into this in
//the inspector panel, the location to teleport to
@HideInInspector
var player : Transform ; //<--the transform of the object this is attached to
function Awake(){
player = transform ; //<--I'm guessing this is why yours wouldn't work. You put
} //your person var at the top for caching, but never cached
//it's value in awake() or start() ; Either that, or you had
//attached your script to some other object and forgot to
//drag&drop your player into the slot for 'person'
function Update(){
if(Input.GetKeyDown(KeyCode.T)){
TeleportMe() ;
}
}
function TeleportMe(){
player.position = teleport.position ;
}
I use c# so my approach is a little different.
I have used the vector3 assignment approach rather that the individual x and y and z approach.
But!!!
can you be sure that the event is fireing?
Place the java equivilant to "Debug.Log(“Q entered”); into your assignemnt routine and inspect the console to see if it is getting fired. Maybe a lowercase Q is being processed.
If the routine is being processed then you will see a message.
That being said, Instead of polling in the Update cycle, why don’t you use the onKeyDown event?
It only gets fired once when the key is pressed. Now again i say that i come from the vb.net (or c#.net) programming world and all my business apps are event driven. I am not sure if this event is available in Java.