Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Closeposition | Center of the sphere. |
radius | Radius of the sphere. |
layerMask | A Layer mask that is used to selectively ignore colliders when casting a ray. |
queryTriggerInteraction | Specifies whether this query should hit Triggers. |
Returns an array with all colliders touching or inside the sphere.
See Also: Physics.AllLayers.
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { void ExplosionDamage(Vector3 center, float radius) { Collider[] hitColliders = Physics.OverlapSphere(center, radius); int i = 0; while (i < hitColliders.Length) { hitColliders[i].SendMessage("AddDamage"); i++; } } }