Have been following this Unity tutorial on Youtube for a side scroller game and writing a script to make a platform move however i keep getting the error BCE0044: expecting EOF, found ‘}’. I’ve tried deleting every single “}” but more errors pop up Please Help
Here is the script
#pragma strict
function Start () {
var Xpos : float;
var Ypos : float;
var max : boolean;
}
var Vert : boolean;
var maxAmount : int;
var step : float;
Xpos = transform.position.x;
ypos = transform.position.y;
}
function Update () {
if(Vert){
if(transform.position.y >= Ypos = maxAmount){
max = true;
} else if(transform.position.y <= ypos){
max = false;
}
} else {
if(transform.position.x >= Xpos = maxAmount){
max = true;
} else if(transform.position.x <= Xpos){
max = false;
}
}
if(Vert){
if(!max){
transform.position.y += step;
} else {
transform.position.y -= step;
}
} else {
if(!max){
transform.position.x += step;
} else {
transform.position.x -= step;
}
}
You have a number of issues here. Part of the issues are matching braces. If you place your cursor at a ‘{’ or a ‘}’ in Monodevelop, the matching bracket will be highlighted. You have missing brackets and extra brackets. To start with, I believe the top of your file should be like this:
#pragma strict
var Xpos : float;
var Ypos : float;
var max : boolean;
var Vert : boolean;
var maxAmount : int;
var step : float;
function Start () {
Xpos = transform.position.x;
ypos = transform.position.y;
}
Note how the declaration of the variables is outside the Start() function. If they were in the Start() function, they would be ‘local’ variables and go out of scope (no longer available) when Start() exited.
Then if you place your cursor on the ‘{’ on line 15, you will see you are missing a closing bracket for the Update() function. Place a ‘}’ at the end of the file.
Once these items are fixed, there are some additional problems. To start with line 20 and line 26 are not correct syntax. I’m not sure what you are trying to do maybe something like:
if (transform.position.x >= Xpos && XPos <= maxAmount) {
Anyway if you are following a tutorial, take a close line-by-line look at the code to see how their syntax differs from yours.
This is the tutorial I’m following apart from the beginning pretty sure I followed it line by line I moved the variables into the function start by random and it cleared up most of the errors except for that one above so I assumed that less errors the better
fixed it thanks for your help and sorry for being a complete noob but i put the variables under the function start in another script but that is working fine could you please explain what you meant by
how the declaration of the variables is outside the Start() function. If they were in the Start() function, they would be ‘local’ variables and go out of scope (no longer available) when Start() exited.