Hello all I have a great request:
I have two gameObject:
-a cube named spawner
-my enemy
I want check the number on my gameObject Enemy are in a defined radius around the cube Spawner.
Thanks
Hello all I have a great request:
I have two gameObject:
-a cube named spawner
-my enemy
I want check the number on my gameObject Enemy are in a defined radius around the cube Spawner.
Thanks
Something is inside a sphere (or circle) if its distance from the center is less than the shape’s radius.
function PointInsideSphere(point : Vector3, center : Vector3, radius : float) {
return Vector3.Distance(point, center) < radius;
}
You could use a loop to call something like that repeatedly, using the transform.position of your spawner and each enemy.
That assumes that you have a list of enemies, somewhere. What if you don’t? It’s possible to build a list of all colliders within a sphere, using Physics.OverlapSphere in 3D or Physics2D.OverlapCircleAll
in 2D. Depending on which you’re using, you can find examples at those links.