I’m trying to code two different idle animations–one for facing right, and one for facing left. By default, my character as of now only plays the idle animation facing right. My code looks like this:
if (Input.GetKey("d"))
{
rb2d.velocity = new Vector2(hSpeed, rb2d.velocity.y);
if (isGrounded)
animator.Play("RunR");
}
else if(Input.GetKey("a"))
{
rb2d.velocity = new Vector2(-hSpeed, rb2d.velocity.y);
if (isGrounded)
animator.Play("RunL");
}
else{
if (isGrounded)
animator.Play("IdleR");
rb2d.velocity = new Vector2(0, rb2d.velocity.y);
I know the best thing to do is to somehow store the last key press as a velocity, and then call that last velocity to determine the correct idle animation (be it “IdleR” or “IdleL”). Can someone explain how to do it?