The trigger to attack is called “Ataque” and the animation of the attack is called “Atacar”
Here is my code:
Animator anim;
Rigidbody2D rb;
public float fuerzaSalto;
public bool enSuelo;
public Transform refPie;
public float velX = 10f;
CircleCollider2D attackCollider;
// Start is called before the first frame update
void Start()
{
anim = GetComponent();
rb = GetComponent();
attackCollider = transform.GetChild(0).GetComponent();
attackCollider.enabled = false;
}
// Update is called once per frame
void Update()
{
float movX;
movX = Input.GetAxis(“Horizontal”);
anim.SetFloat(“absMovX”, Mathf.Abs(movX));
rb.velocity = new Vector2(velX * movX, rb.velocity.y);
enSuelo = Physics2D.OverlapCircle(refPie.position, 1f, 1 << 8); // cuando el pie está cerca del suelo
anim.SetBool(“enSuelo”, enSuelo);
if (Input.GetButtonDown(“Jump”) && enSuelo)
{
rb.AddForce(new Vector2(0, fuerzaSalto), ForceMode2D.Impulse);
}
AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0);
bool Ataque = stateInfo.IsName(“Atacar”);
//animacion de ataque
if (Input.GetKeyDown(“f”) && !Ataque)
{
anim.SetTrigger(“Ataque”);
}
{
}
//girarse
if (movX < 0) transform.localScale = new Vector3(-5, 5, 1);
if (movX > 0) transform.localScale = new Vector3(5, 5, 1);
//camara
{
Camera.main.transform.position = new Vector3(transform.position.x, 0, -20);
}
}