Friends I'm messing with the leap animation of a character and this animation has two sequences, one of when to walk, another to run:
if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.LeftShift))
{
heroiRB.AddForce(new Vector2(0, force), ForceMode2D.Impulse);
PuloLateral();
}
else if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.LeftShift))
{
heroiRB.AddForce(new Vector2(0, force), ForceMode2D.Impulse);
PuloLateral();
}
else if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.D))
{
heroiRB.AddForce(new Vector2(0, force), ForceMode2D.Impulse);
anim.SetBool("PuloLateral", true);
anim.SetBool("Andar", false);
}
else if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.A))
{
heroiRB.AddForce(new Vector2(0, force), ForceMode2D.Impulse);
anim.SetBool("PuloLateral", true);
anim.SetBool("Andar", false);
}
I wanted to create a void method PuloLateral () {} to make it more organized, but I found a certain difficulty when trying this, since it has two sequences, running and walking. Is it possible to leave these two sequences in the same PuloLateral () method? I tried with an If test and did not get the result, only the running skip works:
void PuloLateral()
{
if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.LeftShift) || (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.LeftShift)))
{
anim.SetBool("PuloLateral", true);
anim.SetBool("Correr", false);
}
else if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.D) || Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.A))
{
anim.SetBool("PuloLateral", true);
anim.SetBool("Andar", false);
}
}