Hello. I have recently come across a problem.
I have been trying to change animations using code instead of the Unity Animation Tab because I felt it was more efficient. I have created a switch that changes said animations when the speed reaches a certain point.
switch (PlayerSpeed)
{
case >= 3:
ChangeAnimationState(RUN_SLOW);
break;
case >= 5:
ChangeAnimationState(RUN_SLOWMEDIUM);
break;
case >= 7:
ChangeAnimationState(RUN_MEDIUM);
break;
case >= 9:
ChangeAnimationState(RUN_MEDIUMFAST);
break;
case >= 11:
ChangeAnimationState(RUN_FAST);
break;
}
However from cases 5 to 11 the code is unreachable and error CS8120 appears: The switch case is unreachable. It has already been reached by a previous case or is impossible to match. I want to know if there is some way to limit thhe range of the case similar to that of an if statement such as if (PlayerSpeed >= 5 && < 7) or if I have to do something else. Thanks.
Edit: Apparently one switch statement doesn’t override the other and the top statement is the priority.