Hello! I’m fairly new to Unity and ran into a problem.
So I wanted to make the Dinosaur Game that appears in Google Chrome. One gimmick that the game has is that the speed increases over time, and the faster you go, the faster the dinosaur runs. For this, I made 10 different animations (5 for running and 5 for crouching), and since I didn’t want to have YandereDev code 2.0 I decided to use a switch statement for this. (Ignore the top part as that is the movement)
private void Movement()
{
rb.velocity = new Vector2(PlayerSpeed, rb.velocity.y);
if (PlayerSpeed < 13)
{
PlayerSpeed += speedChangePerSecond * Time.deltaTime;
}
if(IsGrounded())
{
if (IsCrouching() == false)
{
//Animations for walking/running
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;
}
}
else
{
//Animations for crouching
switch (PlayerSpeed)
{
case 3:
ChangeAnimationState(CROUCH_SLOW);
break;
case 5:
ChangeAnimationState(CROUCH_SLOWMEDIUM);
break;
case 7:
ChangeAnimationState(CROUCH_MEDIUM);
break;
case 9:
ChangeAnimationState(CROUCH_MEDIUMFAST);
break;
case 11:
ChangeAnimationState(CROUCH_FAST);
break;
}
}
}
}
However, only the top animation plays, even if the speed changed to 5. The crouching animations don’t display when I press the down key, though the colliders used in there do work as intended.
Is there any way that I can fix the switch so that it works as intended?