I have this code
static var ToggleLight : boolean = true;
function Update () {
transform.Rotate(Vector3.up * Time.deltaTime*10);
if(Vector3.up >= 20 <=180)
{
ToggleLight = false;
}
else{
ToggleLight = true;
}
}
if(Vector3.up == 360)
{
Vector3.up = 0;
}
}
But i got these error:
Assets/Script/LightToggle.js(6,21): BCE0044: expecting ), found ‘’.
Assets/Script/LightToggle.js(6,24): BCE0043: Unexpected token: <=.
Assets/Script/LightToggle.js(6,29): BCE0043: Unexpected token: ).
Assets/Script/LightToggle.js(8,22): BCE0044: expecting :, found ‘=’.
Why?
if(Vector3.up >= 20 <=180)
I haven’t tried it, but try something like:
if((Vector3.up >= 20) (Vector3.up <=180))
You can’t compare the same value twice without specifying it twice. You also need parenthesis around each test as well.
There are a few things wrong with this.
Firstly, with the first if statement, that isn’t the way that C# arguments work, although it makes sense to us, you’re actually telling the compiler to compare 180 with nothing.
Try:
if(Vector3.up >= X Vector3.up <= X)
Secondly, you can’t compare Vector3 with an int, you have to compare it with another Vector.
I’m not really sure what your code is trying to achieve here, as Vector3.up is a world constant, something you can’t change, perhaps you’re looking for transform.up?.
MADmarine
It is for my directly light.
So when is it between 20 degress and 160 degress, it shall change a boolean, so it turn off some lights.
The point he is making is that the code you have won’t work.
Vector3.up is shorthand for Vector3(0, 1, 0). So, for one, it never changes so you’re conditionals would never be true.
Secondly, you’re trying to compare a Vector3 with an integer value. What you’ve written is telling Unity that “When Vector3(0, 1, 0) is greater than or equal to 20”. Doesn’t make any sense.
You should be checking the object’s rotation.
KelsoMRK
Ty My solution were 
transform.position.x instead 