Track only closest enemy transform

How can I achive that I’m only targeting the closest enemy?
Even better would be to “loose” the target if the target comes to close to the player. Jumping on the next target in range, if there is any.

Here is my code:

public class PlayerInput : MonoBehaviour
{
    public Transform target;

    void lookForTarget()
    {
        if (GameObject.FindWithTag("Enemy") != null)
        {
            target = GameObject.FindWithTag("Enemy").transform;
            target.Find("TargetGui").GetComponent<Renderer>().enabled = true;
        }
    }
}

Thanks

Transform enemies = GetEnemies();

float closestDistance = float.MaxValue;
Transform closestEnemy = null;

for(int i = 0; i < enemies.Length; ++i)
{
    float currentDistance = Vector3.Distance(m_player.position, enemies*.position);*

if(currentDistance < closestDistance)
{
closestDistance = currentDistance;
closestDistance = enemies*;*
}
}
In the end, whatever is in closestEnemy will be the one you’re looking for.