Check out Physics.OverlapSphere
It returns all the game objects within a specified sphere. You can specify a layer mask too if need be.
You can either:
Just call OverlapSphere, specifying the spawn point position and radius, then check the returned list of objects for enemies
Or, put all your enemies in their own layer, then just call TestSphere, specifying a layer mask, it’s similar, except it just returns true if there’s anything in the sphere or false otherwise.
I’d write you some code but am on my iPad. Let me know if you need it - I’ll check tomorrow when I have a keyboard handy!
EDIT: Some code…
//this function takes a 3d position, a radius and a layer
//name, and returns true if there are any objects inside the
//layer within a distance of spawn_point_radius from spawn_point_pos
bool TestObjectsInLayer(Vector3 spawn_point_pos, float spawn_point_radius, string layer_name)
{
//first we get the layer id (will be from 0 to 31 depending on how you set it up in the editor)
int layer_id = LayerMask.NameToLayer(layer_name);
//next we construct a 'bit mask' - a 32 bit value, where 0 bits indicate 'ignore layer'
//and 1 bits indicate 'look in this layer'. We set just the bit for our layer. So if
//layer is 4, we set the 4th bit to 1. This is done by shifting the value '1' left by
//layer id bits.
int layer_mask = 1 << layer_id;
//finally, we use the Physics.CheckSphere function to search for objects near the spawn point
return Physics.CheckSphere(spawn_point_pos, spawn_point_radius, layer_mask);
}
That’s a general function for look for objects in a given layer. There is a corresponding version for the 2d physics system (you didn’t say if you were using 2d or 3d colliders), which will look almost identical, but they changed the api slightly just to be annoying!..
//this function takes a 2d position, a radius and a layer
//name, and returns true if there are any objects inside the
//layer within a distance of spawn_point_radius from spawn_point_pos
bool TestObjectsInLayer(Vector2 spawn_point_pos, float spawn_point_radius, string layer_name)
{
//first we get the layer id (will be from 0 to 31 depending on how you set it up in the editor)
int layer_id = LayerMask.NameToLayer(layer_name);
//next we construct a 'bit mask' - a 32 bit value, where 0 bits indicate 'ignore layer'
//and 1 bits indicate 'look in this layer'. We set just the bit for our layer. So if
//layer is 4, we set the 4th bit to 1. This is done by shifting the value '1' left by
//layer id bits.
int layer_mask = 1 << layer_id;
//finally, we use the Physics2D.OverlapCircle function to search for objects near the spawn point
//note: just to be confusing, the 2d api onll provides the 'Overlap' version, which actually returns
//the first collider it finds in the circle, or null otherwise. so we call it and return true
//if any collider was found
return Physics2D.OverlapCircle (spawn_point_pos, spawn_point_radius, layer_mask) != null;
}
With those functions all you need to do is make sure your objects have colliders, and then place them in their own layer (maybe called ‘Enemies’). Then call the function, passing in the spawn point location, size of the area you want to check and the name of the layer you put your objects in. The functions will return true if any objects are already there.
Hope that helps. Sorry if there’s any compile errors - haven’t actually tried the code, but I have written it lots of times over the years 