Problem with float variable in multiple else if conditions.

Hi guys
I’ve a problem with the following script, there are an array of “if else” because for every sensor true, my car turn over direction.

When the centersensor is true the float motor will be negative for reverse turn, but is not working.
I’ve try with a debug and it’s work fine, so I think that the problem is the float motor that is in the end of else condition.
If I modify the else motor with negative it’s work fine, but I want negative only if centersensor is true.

Can you help me?

THK

        else if (rightsensor == true)
        {
            motor = 1f;
            steering = -25;
        }
        else if (centersensor==true)
        {
            steering = -25;
            motor = -maxMotorTorque * Time.deltaTime * 10;
        }

        else if (rightsensor == true && rightsensorangle == true)
        {
            steering = -25;
               }
        else
            steering = (relativeVectore.x / relativeVectore.magnitude) * maxSteeringAngle;
        motor=maxMotorTorque* Time.deltaTime*10;

I think you are using else if with no sense… you should read about if and else if…

Look, your first else if is

rightsensor == true

your 3rd else if is

rightsensor == true && rightsensorangle == true

But this have no sense, because if

rightsensor == true

it will enter at the first else if, and will never arrive to the 3rd, or the 2nd or any other else if or else in that iteration… so with this code, 3rd elsif will neber be reached, never.

Bye.