var distanceToPlayer = Vector3.Distance(transform.position, targetplayer.position);
and when distance to player is smaller than my spawnrange instantiate the bad guys all OK.
however it is checking the distance in all direction,
I'm using it in a scene in a multi story carpark (lots of floors ontop of each other) and when I am on the floor below I'm triggering the spawns point on the floor above.
So can anyone help
I need to check the distance but only on the X + Z axis (on a horizontal plane not vertically)
I probably wouldn't calculate the distance to the player every frame, it'd probably be more efficient to give the spawnpoint a sphere collider, and flatter the collider so its more of a flat circle. Then just use OnTriggerEnter() and OnTriggerExit() to detect the player.
If you are dead set on calculating the distance, I would use the square magnitude instead, as it is much less resource-intensive.