Not playing animation after been hit by bullet

Hello guys. I’m going around here in my 2d wannabe game with an animation to play on the bad guy after being hit by the bullet. I can not make her run. I can get the enemy destroyed but not play the animation first. I thought it might be for destroying the gameObject first so I put time to be destroyed but the animation still does not run and Unity does not give any error. Here is the bad guy script.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BadguyScript : MonoBehaviour
{
    public int maxHealth;
    public int curHealth;

    void Start()
    {
        maxHealth = 1;
        curHealth = maxHealth;

    }
    void Update()
    {
        if (curHealth < 1)
        {          
            Destroy(gameObject,2f);
            GetComponent<Animation>().Play("dead_anima");
        }
    }
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag == "bullet")
        {
            curHealth -= 1;
            Destroy(col.gameObject);
        }
    }
}

Any help , please?

Well for most controllers of any entity, you’d have in your Animator

  1. Locomotion (this represents your movement and idle states, usually a blend tree so you can quickly switch between Idle, Walk, and Run without ever defining more than a float)
  2. Combat (this is all your attacks, hits, and death animations, usually you would use a sub tree here to move between them)
  3. Complex Movement (jumping, rolling, whatever else)

Then you’d have your parameters like

  1. speed : float //would used by the locomotion blend tree to determine which animation to play, if speed is 0 then idle, speed is > 0 < 1 then walking, if speed is 1 then running.
  2. attack : trigger //would move the animator to your attack animation, if you have more than 1 then you’d use the next parameter as well
  3. random : int //to determine random things, like if you have multiple attacks and want to play a specific or random one, you would have transition parameter of trigger attack AND random == x;
  4. death //would move the animator to death animation, and be sure to prevent looping, and would stop at death animation.
  5. hit //would move the animator to being hit animation

As well you can use Animation events to in-depthly control what happens during the animations. AnimationEvent parameters are String, Int, Float, Object, and can be VERY useful when passing information. For example when your player OR enemies attack, you’d want to add an event to the attack animation to call on the hit function to see if someone is within hit range and then pass that damage info to the appropriate entity. Sorry if this is all going over your head :frowning:

I changed my code, using animator component and the hit animation is playing now. Thank you all.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BadguyScript : MonoBehaviour
{
    public int maxHealth;
    public int curHealth;
    private Animator myAnimator;

    void Start()
    {
        myAnimator = GetComponent<Animator>();
        myAnimator.enabled =true;
        myAnimator.SetBool ("isDead",false);


        maxHealth = 1;
        curHealth = maxHealth;

    }
    void Update()
    {
        if (curHealth < 1)
        {

            myAnimator.SetBool ("isDead",true);
            Destroy(gameObject,2.5f);
        }
    }
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag == "bullet")
        {
            curHealth -= 1;
            Destroy(col.gameObject);
        }
    }
}