- Home /
C# Error with if statement
i have this bit of code
void Update () { if (gear = 1 ) rlight1.enabled = true; rlight2.enabled = true;
else if (gear > 1 )
rlight1.enabled = false;
rlight2.enabled = false;
}
and have the variables set up, but it's telling me to put a semicolon on this line :
else if (gear > 1 )
waht is happening and how do i fix it?
Answer by ron3fp · Sep 08, 2010 at 07:32 PM
You need to add braces, only single lines can be written without:
void Update () {
if (gear == 1 ) {
rlight1.enabled = true;
rlight2.enabled = true;
} else if (gear > 1 ) {
rlight1.enabled = false;
rlight2.enabled = false;
}
}
okay, now it's saying it cant convert int to bool on line 2 there (this is being added to the drivetrain script from the alternate physics model in the car tut.
because there's an assignment statement not a boolean comparison. change gear = 1 to gear == 1.
yes that's right - escaped my attention as well. gear = 1 needs to be gear == 1 :)
okay, no errors now, but the reverse lights stay on and won't turn off. :(!
Sounds like gear is less than or equal to 1. Add some debug code to verify this: Debug.Log (string.Format ("gear = {0}", gear));
Your answer
![](https://koobas.hobune.stream/wayback/20220613072930im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UCE0001: ';' expected. Insert a semicolon at the end. 2 Answers
Problem with my Hack and Slash tutorial Health bar script 1 Answer
doing force and spin on a gameobject when clicking on plane. 2 Answers
UCE0001: ';' expected. Insert a semicolon at the end." 1 Answer
help with UCE0001: ';' expected. Insert a semicolon at the end 3 Answers