Enemy attack target

How do i make so when the enemy comes within a attack radius its damaging the target there is 2 different targets there is a building and there is a player so how do i make it attack the target there is within attack radius this is the script

void Update()
{
    TargetFinder();

    if (currentTargetDistance < attackRadius)
        Attack();

    if (myTarget == null)
        currentTargetDistance = searchRadius;
    else
        Move(myTarget.transform);

    if (CurrentHealth < DeathHealth)
    {
        print("Enemy Has died!!!");
        Destroy(GroundEnemy);
    }

    print("Enemy took some damage");
}

void TargetFinder()
{
    foreach (var x in Targets)
    {
        float distance = (transform.position - x.transform.position).magnitude;

        if (distance < currentTargetDistance)
        {
            myTarget = x;
            displayText.text = "My target: " + x + "

Distance to Target: " + distance; //skal fjernes nå det er helt klart
currentTargetDistance = distance;
}
}
}

void Move(Transform t)
{
    transform.LookAt(t);
    transform.position += transform.forward * MoveSpeed * Time.deltaTime;
}

void Attack()
{
    Targets.Remove(myTarget);
    Destroy(myTarget);
    myTarget = null;
    currentTargetDistance = searchRadius;
}

Hi, one of the problems may be that your top two if statements do not have curly brackets. However, I would recommend a different approach to the whole thing. I would put a collider on your player (you can change the size to your liking) as the radius. Make sure it is checked as a trigger, and then use

 void OnTriggerEnter(Collision col)
 {
     if (col.gameObject.name == ("Enemy's name")
         {
             //Attack code
         }
 }

Put this code directly on your player and don’t forget to put the collider on. I hope any of this helps!