Hi my animation not working . i think it is because of animator ..please help @LatchGameDev

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

public class DamageEnemy : MonoBehaviour
{
// Start is called before the first frame update

[SerializeField]  int EnemyHealth = 100;
private AudioSource MyPlayer;
[SerializeField] AudioSource StabPlayer;
private bool HasDied = false;
private Animator Anim;
 

void Start()
{
    MyPlayer = GetComponent<AudioSource>();
    Anim.GetComponentInParent<Animator>();
    
}

// Update is called once per frame
void Update()
{
    if (EnemyHealth <= 0)
    {
        Debug.Log("hahahahah");
        if (HasDied == false)
        {             
            Anim.SetTrigger("Death");
            HasDied = true;
        }
    }
}



private void OnTriggerEnter(Collider other)
{
    if (other.gameObject.CompareTag("Axe"))
    {
        EnemyHealth -= 50;
        MyPlayer.Play();
        StabPlayer.Play();
        
    }
}

}

@LatchGameDev

you are trying to access the component of the animator using a reference that isn’t there.

Essentially you are trying to get an Animator component on the parent of your “Anim” reference that isn’t set anywhere.

To fix this you can reference the animator component on the inspector directly using the [SerializeField] attribute on the Animator Anim, like this [SerializeField] Animator Anim;
or fix you code on the Start by changing it to

 void Start()
 {
     MyPlayer = GetComponent<AudioSource>();
     Anim = GetComponentInParent<Animator>();
  }   

of course this will only work if on there is an Animator component on the parent of gameObject that holds this script