Stopping an animation when key is unpressed
Hi, i'm making a 2D game where you press 'A'/'D' to move left and right and 'LeftShift' to run. How would I make it so when I lift the 'LeftShift' key, the run animation would stop? Currently, when I hold 'LeftShift' even without moving it plays the run animation and when I move and press 'LeftShift' then let go of the move keys it still plays the run animation.
Here's the code: (Sorry if it's a disaster)
if (Input.GetKey(KeyCode.A) && Input.GetKeyDown (sprintKey)) {
moveSpeed *= sprintMultiplier;
anim.SetBool ("Sprint", true);
} else if (Input.GetKeyUp (sprintKey)) {
moveSpeed = originalSpeed;
anim.SetBool ("Sprint", false);
}
if (Input.GetKey(KeyCode.D) && Input.GetKeyDown (sprintKey)) {
moveSpeed *= sprintMultiplier;
anim.SetBool ("Sprint", true);
} else if (Input.GetKeyUp (sprintKey)) {
moveSpeed = originalSpeed;
anim.SetBool ("Sprint", false);
}
Any help would be appriciated :)
Thanks.
Your answer
Follow this Question
Related Questions
Animation/Movement Error 1 Answer
Moving GameObject a specific distance in the Z direction and back again - regardless of rotation 1 Answer
Setting another script's property from code doesn't actually set the property 1 Answer
Make Ball roll without imput 0 Answers
SetBool animation state based on direction object is moving 0 Answers