How to make enemy that needs to be hit X amount of times to be destroyed,How to make an enemy kill script with hp that destroys it after x amount of hits using collision based triggering


I am very new to coding and have been living off of tutorials my entire time coding.

Basically, I have already have a sword that can deal contact triggers to do anything. What I need is a script for my enemies that will give them modifiable HP that causes them to be destroyed after being hit X amount of times.

Here’s my sword script

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

public class Melee_Combat : MonoBehaviour
    Animator anim;

    // Start is called before the first frame update
    private void Start()
        anim = GetComponent<Animator>();

    // Update is called once per frame
    private void Update()
            anim.SetBool("attacking", true);
        else if (Input.GetButtonUp("Fire1")) 
            anim.SetBool("attacking", false);

Just need to create a function that is called on hit detection, and this function access a script on the enemy and change its Hp and check if is <= 0 to destroy the enemy object