- Home /
Question by
damir_2009 · Mar 04 at 03:33 PM ·
c#unity 5visual studiounity 4.6
if (Input.GetKeyDown("w")) Not working
Hello, I tried to make a code for my animations and I wrote this:
if (Input.GetKeyDown("w")) { animatorz.Play("SlowRun"); Debug.Log("ya"); }
Technically it all worked BUT when i press W and then for example A while pressing W i let go from A and it send me back to idle state but i was still pressing W, is there a way to make it properly like in actual games? Thanks!
Comment
Answer by Lenny991 · Mar 04 at 04:08 PM
I don't have a fix for this particular problem but there is a workaround that would be more performant and in most ways just better, Input.GetAxis.
here is some code from a project of mine
Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
//rb is a Rigidbody2D;
rb.velocity = input*movementSpeed;
then you can for example use a blend tree to have smooth animations, or if that is too much work just use
if(rb.velocity != new Vector2(0, 0))
animatorz.Play("SlowRun");