Sprinting animation and back to idle

Hello I am new to unity, i’ve had this problem that my sprint animation wont start and go back to idle.

Could someone help me fix this? Thanks.

        if (Input.GetButtonDown("Sprint") && Input.GetKey(KeyCode.W))
        {
            anim.CrossFadeInFixedTime("Sprint", 0.01f);
        }
       else// if (Input.GetButtonUp("Sprint"))
        {
            anim.CrossFadeInFixedTime("Idle", 0.01f);
        }

You’re doing Input.GetKey(), this means every frame that you’re holding down “w”, it’s going to re-call anim.CrossFadeInFixedTime("Sprint", 0.01f);. Change it to GetKeyDown. Though you could also check “If animation “Sprint” not playing, then do this crossfade”. So you wouldn’t need to worry about it replaying each time they tap the key.

Thank you, I will try this out.