- Home /
Question by
ItzIpsyy · Aug 29, 2016 at 12:45 PM ·
scripting problemscript error
BCE0044: expecting EOF, found '}'.
var speed = 2.0;
function Update() {
var v3 = Vector3(Input.GetAxisRaw("Horizontal"), 0.0, Input.GetAxisRaw("Vertical"));
transform.Translate(speed * v3.normalized * Time.deltaTime);
}
if(Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) {
v3 += Vector3.forward;
}
if(Input.GetKey(KeyCode.S)||Input.GetKey(KeyCode.DownArrow)) {
v3 += Vector3.back;
}
if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) {
v3 += Vector3.left;
}
else if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) {
v3 += Vector3.right;
}
}
Comment
Answer by Landern · Aug 29, 2016 at 12:48 PM
Your set of if/if/else statements aren't in a function block, you need to remove the ending curly from Line 6 of the script example to include the keyboard checks.
Like so:
var speed = 2.0;
function Update() {
var v3 = Vector3(Input.GetAxisRaw("Horizontal"), 0.0, Input.GetAxisRaw("Vertical"));
transform.Translate(speed * v3.normalized * Time.deltaTime);
if(Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) {
v3 += Vector3.forward;
}
if(Input.GetKey(KeyCode.S)||Input.GetKey(KeyCode.DownArrow)) {
v3 += Vector3.back;
}
if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) {
v3 += Vector3.left;
} else if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) {
v3 += Vector3.right;
}
}
Your answer
Follow this Question
Related Questions
Movement Script stops working 0 Answers
Having trouble using SendMessage 1 Answer
How to control ios statusbar with script? 1 Answer
How can i set transform.position on y ? And why i'm getting error cannot convert double to float ? 3 Answers
Object flashing in and out every frame (because of my script) 0 Answers