I am working on creating a respawn script in Javascript and I am getting three “BCE0043 Unexpected token: …” errors when I try to run the program. They are on lines 7-9, all three of the variables in the Start function. Here is my code:
#pragma strict
var Position = {};
function Start () {
var Position.startX = gameObject.transform.position.x;
var Position.startY = gameObject.transform.position.y;
var Position.startZ = gameObject.transform.position.z;
}
function Update () {
}
function OnTriggerEnter (other : Collider) {
if (other.name == "Player"){
other.transform.position = Vector3(Position.startX, Position.startY, Position.startZ);
}
}
Any help would be greatly appreciated. Thanks in advance.
Actually, nevermind, I completely changed my code to work in Vector3 correctly. Here it is if this helps anyone else:
#pragma strict
var playerPosition : Vector3;
function Start () {
playerPosition[0] = gameObject.Find("Player").transform.position.x;
playerPosition[1] = gameObject.Find("Player").transform.position.y;
playerPosition[2] = gameObject.Find("Player").transform.position.z;
}
function Update () {
}
function OnTriggerEnter (other : Collider) {
if (other.name == "Player"){
other.transform.position = playerPosition;
}
}
Not quite sure why you’re trying to use a hashtable for that; just use a Vector3.
private var startPosition : Vector3;
function Start () {
startPosition = transform.position;
}
function OnTriggerEnter (other : Collider) {
if (other.name == "Player") {
other.transform.position = startPosition;
}
}