Can you pass a degree through a SWITCH statement?

Would like to pass the result of a Vector3.Angle through a switch but it won’t accept it. Any way around it rather than multiple if statements?

float angle = Vector3.Angle (localVelocity, desiredVelocity);
            if (angle <= 180)
                turnSmooth = 2.5f;
            if (angle <= 90)
                turnSmooth = 1.5f;
            if (angle <= 45)
                turnSmooth = 0.5f;

Nope. Switch-case doesn’t really work when you need a range of values, or if you need to compare a case to a variable. With switch statements you have to make the cases all constant so they are known at compile time. There can’t be any calculations done with the cases at run time.

If you find all the if statements ugly, you can stick them in another function. Then just do a turnSmooth = GetTurnSmoothFromAngle(angle);

1 Like

Garth beat me to the punch, but if you’re wondering why:

1 Like

If statements it is then. Thanks for the info.