Version: 2018.3 (switch to 2019.1)
LanguageEnglish
  • C#

Physics.OverlapSphere

public static Collider[] OverlapSphere(Vector3 position, float radius, int layerMask = AllLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);

Parameters

positionCenter of the sphere.
radiusRadius of the sphere.
layerMaskA Layer mask that is used to selectively ignore colliders when casting a ray.
queryTriggerInteractionSpecifies whether this query should hit Triggers.

Description

Returns an array with all colliders touching or inside the sphere.

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++; } } }

Did you find this page useful? Please give it a rating: