- Home /
If...else statement with errors
I'm new to Unity, and I have a lot of trouble scripting. I always get compile errors. I made this script to open a door. When I saved it it had two compile errors:
Assets/DoorOpen.js(12,11): BCE0044: expecting }, found 'else'. Assets/DoorOpen.js(8,13): BCE0043: Unexpected token: doorOpen.
Here is the script:
var doorOpen : boolean;
var selectedUnits : Array = new Array();
function OnMouseOver (){
if(selectedUnits.length <= 0){
if(Input.GetMouseButtonDown(0)){
If (doorOpen = true);
{
transform.Rotate(0, 90, 0);
transform.position = Vector3(1218.346, 7.315172, 902.15);
} else {
transform.Rotate(0, 90, 0);
transform.Translate = Vector3(1220.346, 7.315172, 902.15);
}
}
}
Someone please help!
If (doorOpen = true); it should be If (doorOpen == true) Remove ';' and add = ....
Answer by YoungDeveloper · Feb 02, 2014 at 06:15 PM
It's if not If
You are ending statement on line 8 with semicolon. Should be:
if(){
}
Thanks, now my code looks like this:
var doorOpen : boolean = false;
var selectedUnits : Array = new Array();
function On$$anonymous$$ouseOver (){
if(selectedUnits.length <= 0){
if(Input.Get$$anonymous$$ouseButtonDown(0)){
if(doorOpen == true){
transform.Rotate(0, 90, 0);
transform.position = Vector3(1218.346, 7.315172, 902.15);
} else {
transform.Rotate(0, 90, 0);
transform.Translate = Vector3(1220.346, 7.315172, 902.15);
}
}
}
}
...but I'm getting this error message: Assets/DoorOpen.js(13,45): BCE0031: Language feature not implemented: Ambiguous(Void Translate(Vector3), Void Translate(Vector3, Space), Void Translate(Single, Single, Single), Void Translate(Single, Single, Single, Space), Void Translate(Vector3, UnityEngine.Transform), Void Translate(Single, Single, Single, UnityEngine.Transform)).
Translate is a method and you are using it like a variable. What you need is a program$$anonymous$$g book.
Your answer
Follow this Question
Related Questions
One use per level question 1 Answer
Gestures in javascript 4 Answers
How can I use 1 key instead of two for toggling animation ? 2 Answers
Take boolean from other script error 1 Answer
Creating a Loadout 1 Answer