Overlap.Sphere

so I’m trying to make a destroy everyone within radius and thought overlap sphere would be best bet but cant seem to write the right code to destroy other game objects everything I try just destroys my player right away. ive made a layer mask and changed it in inspector and was still doing it.

any help would be awesome :smiley:

    public float radius = 0f;
public Collider[] colliders;
public LayerMask mask;

void LateUpdate ()
{
	colliders = Physics.OverlapSphere (transform.position, radius, mask);

	foreach (Collider col in colliders)
	{
            // destroy game objects in radius here
	}
}

}

Try Physics.OverlapSphereAll. As far as I know, OverlapSphere returns only the first object it finds. OverlapSphereAll returns every object it finds within the radius. I don’t get why the player gets still destroyed though. The Layermask should be set to everything you want to destroy, so everything except the Player Layer I guess. Hope this helps :slight_smile: