- Home /
Question by
DanielSturk · Dec 22, 2012 at 11:23 PM ·
javascripterrorgameobject
exspecting EOF, found '}'.
I keep getting this error, but I don't see an extra } anywhere. #pragma strict
function Start () {
static var camx = transform.position.x;
static var camy = transform.position.y;
static var camz = transform.position.z;
}
function Update () {
if(Input.GetKey("a")){
transform.position.x+=1;
}
camx = transform.position.x;
camy = transform.position.y;
camz = transform.position.z;
}
Comment
Best Answer
Answer by liszto · Dec 23, 2012 at 12:29 AM
I think those lines are better :
static var camx;
static var camy;
static var camz;
function Start () {
camx = transform.position.x;
camy = transform.position.y;
camz = transform.position.z;
}
function Update () {
if(Input.GetKey("a"))
{
transform.position = Vector3( transform.position.x + 1, transform.position.y, transform.position.z );
}
camx = transform.position.x;
camy = transform.position.y;
camz = transform.position.z;
}
Answer by sparkzbarca · Dec 22, 2012 at 11:25 PM
transform.position.x+=1;
thats not legal
x can't be assigned to it returns x thats all. You cant assign them individually like that.
You can in JavaScript, and this script is js. Also, it would throw a different exception.
Answer by Piflik · Dec 23, 2012 at 12:20 AM
You cannot declare static variables inside Start(). You have to declare them outside of any functions, if you want them static, since variables defined in functions are always local.
Your answer
![](https://koobas.hobune.stream/wayback/20220613085824im_/https://answers.unity.com/themes/thub/images/avi.jpg)