- Home /
Unity C# Two keys pressing one after another not doing a function vice versa
I have made this movement code for my player (Excerpt):
if(Input.GetKey("w") && Input.GetKey(KeyCode.LeftShift))
{
transform.Translate((Vector3.forward) * runSpeed * Time.deltaTime);
anim.SetFloat("Speed", runSpeed);
}else if (Input.GetKeyUp(KeyCode.LeftShift))
{
transform.Translate((Vector3.forward) * walkSpeed * Time.deltaTime);
anim.SetFloat("Speed", walkSpeed);
}
I have tested this, and it works when I hit shift, and then "w" ( Or both at the same time), but when I hit "w", and then "shift", my character stays in it's walking animation, but speeds up. How can I make it so that when I am walking (Pressing "w"), then press "shift", my character plays the running animation, and speeds up?
EDIT: Never $$anonymous$$d. I fixed the problem. It was my animator controller. I forgot to put in the transition between the Walk and Run animation.
Your answer
Follow this Question
Related Questions
Play Animation With GetKey 1 Answer
C# Input.GetKey("Tab") Double Tap 1 Answer
Multiple Cars not working 1 Answer
How to prevent an animation from triggering more than on due to fast clicking? 2 Answers
Animation Input / ETC 1 Answer