Hello! I need help at my melee script Unity 2D

Hello,I am currently working on the melee part and I need some help.My game is a mobile game and every tutorial i find is for PC.I want to make the Main Character to take damage if he collides with an enemy.Also the Main Character could attack the enemy if he is close by. I am new to Unity programming and I will be very thankful if ill get even only a hint.Thanks!
P.s. I got the script ideas from Brackeys.
MainCharacter’s Damage Script

public Transform attackPoint;
public float attackRange = 0.5f;
public LayerMask enemyLayers;
public void Attack()
{
    Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(attackPoint.position, attackRange, enemyLayers);
    foreach(Collider2D enemy in hitEnemies)
    {
        Debug.Log("We hit" + enemy.name);
    }

}

// Update is called once per frame
void Update()
{
    
}
    void OnDrawGizmosSelected()
    {
        if(attackPoint == null)

        Gizmos.DrawWireSphere(attackPoint.position, attackRange);

    }

Health Bar script
public Slider slider;

public void SetMaxHealth(int health)
{
    slider.maxValue = health;
    slider.value = health;
}

public void SetHealth(int health)
{
    slider.value = health;
}

Hey,

Firstly, good shout on using Brackeys as resource. I’ve learned a lot from that dude.

There are a few things missing. Maybe they are a part of other scripts but from the code you’ve shared, there is no trigger for the function Attack(). In the scenario of a character striking an enemy, this function should be called on a button (virtual in mobile) press. Currently nothing is calling the Attack function so it’s not being implemented.
For your bump / walk into damage effect, where a character can injure or get injured by an enemy by moving into it, the trigger for the Attack function can be called by the built in function “OnCollisionEnter” or “OnTriggerEnter” (or their 2D alternatives if you are making a 2D game). The above functions are very useful for detecting when gameobjects collide with each other.