position | Centro de la esfera. |
radius | Radio de la esfera. |
layerMask | A Layer mask defines which layers of colliders to include in the query. |
queryTriggerInteraction | Especifica si esta consulta debería golpear Triggers. |
Collider[] Retorna un arreglo con todos los colliders que se están tocando o están dentro de la esfera.
Computes and stores colliders touching or inside the sphere.
See Also: Physics.AllLayers. Allocates memory. Consider using Physics.OverlapSphereNonAlloc instead.
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { void ExplosionDamage(Vector3 center, float radius) { Collider[] hitColliders = Physics.OverlapSphere(center, radius); foreach (var hitCollider in hitColliders) { hitCollider.SendMessage("AddDamage"); } } }
See Also: Layer mask particularly "Casting Rays Selectively" for a detailed example of Layer masking.