How do I play a certain animation on keydown?
I am trying to make a game but I can't figure out on how to change the Integer value by pressing and holding a certain key. For example I want to make the left arrow move my sprite left and at the same time play my Walk animation. I need it to somehow change the Integer value to 1 for the transition.
Answer by Noodles_yummy · Feb 01, 2018 at 04:04 AM
I'm not sure if this helps considering I'm really new, but to change animations I just made an int parameter called "speed" in my player animator and then connected it to my player controller script like this anim = GetComponent(); //placed under void start
anim.SetFloat("speed", Mathf.Abs(Input.GetAxis("Horizontal"))); //placed under fixed update
and then in my transitions I set the parameter to "if "speed" is more than "0.01" " and then switching back to idle if "speed" is less than "0.01". I don't know if this will work for you, it worked for me, but it might depend on how your player controller is set up. I just have the horizontal axis thingy where it automatically chooses "A" and "D" as your keys, plus the arrow keys. But again, I'm a noob and really hopes this helps :)