- Home /
Why is there an unexpected token error?
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.
Answer by Eric5h5 · Apr 04, 2012 at 12:51 AM
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;
}
}
Answer by nikemikey3 · Apr 04, 2012 at 12:59 AM
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;
}
}
Take a look at my answer; you can just assign a Vector3, you don't need to do x, y, and z separately.
Indeed, you don't have to make manually a copy of the Vector3 because it is not a reference-type but a value-type. Thus assignation always makes a copy.
Your answer
Follow this Question
Related Questions
Unexpected token: private. Error. Can anyone help? 2 Answers
Javascript Expecting Errors ';' & '=' 0 Answers
unexpected token: savedTime 1 Answer
[JavaScript Error] BCE0043: Unexpected token: 2 Answers
Setting Scroll View Width GUILayout 1 Answer