Hi I’m trying to make my player “die” in a tech demo I’m making so I want them to teleport to the start of the map. I’m currently using the following code but it isn’t reacting to the object.
Any feedback is appreciated. I am new to unity and Java scripting so I may have made a simple error without realising
First off, for code use the [ CODE ] tag, like so.
var targetObj : Transform; //The target of the trigger
var proximity : float = 1; //Creates a proximity for the object
var player : Transform;
function Update ()
{
var dist = Vector3.Distance(targetObj.transform.position, transform.position);
if (dist < proximity)
{
player.transform.position = Vector3 (0,10,0);
}
}
Second, I’m guessing you meant to compare the distance between the targetObj and the player’s position, not the transform of the object the script is attached to. So change
var dist = Vector3.Distance(targetObj.transform.position, transform.position);
To
var dist = Vector3.Distance(targetObj.transform.position, player.transform.position);