how to make Attack enemy with min distance
I am also new to unity but dont know if this will work but you can try.
add a gameobject to your main player and add a circle collider component to it, set it’s radius to that range in which you want your player to shoot at an enemy. give this gameobject a “tag” then check its collision with the enemy.
Correct me if I am wrong.
use this first fine the distance between two point using
distance = player.transform.position - enemy.transform.position;
then find its square magnitude using distance = float magnitude = distance.sqrMagnitude;
now use
if(magnitude < yourMinDistance)
{
Attack();
}