Physics.OverlapSphereNonAlloc

Cambiar al Manual
public static int OverlapSphereNonAlloc (Vector3 position, float radius, Collider[] results, int layerMask= AllLayers, QueryTriggerInteraction queryTriggerInteraction= QueryTriggerInteraction.UseGlobal);

Parámetros

positionCentro de la esfera.
radiusRadio de la esfera.
resultsEl buffer donde se almacena los resultados.
layerMaskA Layer mask defines which layers of colliders to include in the query.
queryTriggerInteractionEspecifica si esta consulta debería golpear Triggers.

Valor de retorno

int Returns the amount of colliders stored into the results buffer.

Descripción

Calcula y almacena los colliders que se tocan o están dentro de la esfera en el buffer proporcionado.

Does not attempt to grow the buffer if it runs out of space. The length of the buffer is returned when the buffer is full. Like Physics.OverlapSphere, but generates no garbage. See Also: Physics.AllLayers.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void ExplosionDamage(Vector3 center, float radius) { int maxColliders = 10; Collider[] hitColliders = new Collider[maxColliders]; int numColliders = Physics.OverlapSphereNonAlloc(center, radius, hitColliders); for (int i = 0; i < numColliders; i++) { hitColliders[i].SendMessage("AddDamage"); } } }

See Also: Layer mask particularly "Casting Rays Selectively" for a detailed example of Layer masking.