How can I use my current code to make OnTriggerEnter2D damage system?

I have this line of code that I followed from a video and I need help on a new script that will apply damage of 1 heart to the health bar/system whenever the player on collision touches a tag “enemy” gameObject.
I’m trying hard to study code independantly from online sources so sorry if what I try to ask is confusing.

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

public class HealthBar : MonoBehaviour
{
    public int currentHealthBar;
    public int maxHealthBar;

    public Image[] hearts;
    public Sprite fullHeart;
    public Sprite emptyHeart;

    void Start()
    {

    }

    void Update()
    {
        updateHealth();
        KeyCodeinput();
    }

    public void updateHealth()
    {
        if (currentHealthBar > maxHealthBar)
        {
            currentHealthBar = maxHealthBar;
        }

        for (int i = 0; i < hearts.Length; i++)
        {
            if (i < currentHealthBar)
            {
                hearts*.sprite = fullHeart;*

}
else
{
hearts*.sprite = emptyHeart;*
}

if (i < maxHealthBar)
{
hearts*.enabled = true;*
}
else
{
hearts*.enabled = false;*
}
}

}

public void KeyCodeinput()
{
if (Input.GetKeyDown(KeyCode.Space))
{
currentHealthBar -= 1;
}
}

}

Something like this:

   void OnTriggerEnter2D(Collider other)
    {
        if (other.CompareTag("enemy")
        {
            currentHealthBar -= damage; // Damage needss to be whatever amount should be taken
            UpdateHealth();
        }
    }

I added UpdateHealth() as you can simply ad that code to the end of each function that changes health instead of every frame.