How to set the Animator for a fighting game?

Hello, I’m new in Unity and I need your help. I’m doing a fighting game, where the enemies attack my player. I didn’t had any problems with writing code, but when I started sorting the animations on the animator, it didn’t work very well. At the beginning, my first enemy did the right moves. But even if I copied the same thing to my second enemy, it wasn’t dying. So I played around with the animator and couldn’t find any solution. It would make me very happy, if someone who has experience with 2D combat could help me solving these.

Hello and thx for your answer. I changed my animator, but the problem now is that the death animation doesn’t work, like the enemy disapears befor playing the death animation". Here you have my enemy code and the animator:
[182812-unbenannt34.png|182812]

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
    public Animator animator;

    public Transform player;
    public int maxHealth;
    int currentHealth;
    public float speed;
    public float distance;
    private Vector2 movement;
    public int attackDamage = 40;
    public float attackRate = 2f;
    
    private Rigidbody2D rb;

    // Start is called before the first frame update
    void Start()
    {
        currentHealth = maxHealth;
         rb = this.GetComponent<Rigidbody2D>();
        
    }

    void Update () {
            if (player.position.x < transform.position.x && facingRight){
            Flip ();
            }
            if (player.position.x > transform.position.x && !facingRight){
            Flip ();
            }

            if(Vector2.Distance(player.position, transform.position) > distance)
            {
                transform.position = Vector2.MoveTowards(transform.position,player.transform.position, speed*Time.deltaTime);
                animator.SetTrigger("movement");
                animator.SetBool("Attack",false);

            }
            if(Vector2.Distance(player.position, transform.position) < distance){
                
                Attack();
            }
    }
    

    public void TakeDamage(int damage)
    {
        currentHealth -= damage;

        animator.SetTrigger("Hurt");

        if(currentHealth < 0)
        {
            Die();
            Disapear();
            
        }
    }

    void Die()
    {

        animator.SetBool("IsDead", true);

        this.enabled = false;
        GetComponent<Collider2D>().enabled = false;

       
    }

    void Disapear(){
        
        GameObject.Destroy(gameObject,2);
    }
    public bool facingRight = false;
    
    void Flip () {
    facingRight = !facingRight;
    Vector3 tmpScale = gameObject.transform.localScale;
    tmpScale.x *= -1;
    gameObject.transform.localScale = tmpScale;
    }

   void Attack() {

        animator.SetTrigger("Attack");
        

    }
 

}

Hi @Yeniyi , this is because the animator you’ve set, to go into the death animation need to have

 animator.SetTrigger("Hurt");

and

animator.SetBool("IsDead", true);

in the same time…

Using your code, it trigger the Hurt animation, but the “isDead” will be false, so it stop the tree.

To resolve this, just connect “AnyStates” to “Death” animation like you’ve done before…

In this way, in the instant into you set “isDead = true” the death animation will starts.