Question by
bearz3816 · May 18, 2020 at 05:31 AM ·
2d game2d sprites2d animation
Why my 2D Sprite runing Animation only works when i move to the left? HELP PLS
Hi im new on all this wolrd of developing 2d games on Unity. In a couple days i designed a couple characters pixel based and i made an animation that simulate the player runing. Now my player can move to the left and right and thats cool but also added my running animation when i press "A" to the left and "D" to the right, here is where the problem comes. I watched some tutoriales to do this possible but actually the runing animation only works when i press the "A" but when i press "D" the runing animation didnt work :/ Here is my code at the moment, i hope and someone can help me it would be awesome, thanks and good day :p or if someone know a different way to do it I'd really appreciate it.
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.D))
{
pos.position += new Vector3(1f, 0, 0) * speed * Time.deltaTime;
buttle.flipX = false;
anim.SetBool("caminarder", true);
} else {
anim.SetBool("caminarder", false);
}
if (Input.GetKey(KeyCode.A))
{
pos.position -= new Vector3(1f, 0, 0) * speed * Time.deltaTime;
buttle.flipX = true;
anim.SetBool("caminar", true);
} else{
anim.SetBool("caminar", false);
}
if (Input.GetKeyDown(KeyCode.Space))
{
sal.AddForce(Vector2.up * fsal, ForceMode2D.Impulse);
}
}
}
Comment