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.
Close Submission failedFor 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.
Close Your name Your email Suggestion* Declarationpublic static int
OverlapSphereNonAlloc(
Vector3 position, float
radius, Collider[]
results, int
layerMask= AllLayers,
QueryTriggerInteraction queryTriggerInteraction= QueryTriggerInteraction.UseGlobal);
Parameters Parameter Description position Center of the sphere. radius Radius of the sphere. results The buffer to store the results into. layerMask A Layer mask defines which layers of colliders to include in the query. queryTriggerInteraction Specifies whether this query should hit Triggers. Returnsint Returns the amount of colliders stored into the results
buffer.
Computes and stores colliders touching or inside the sphere into the provided buffer.
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. Additional resources: 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"); } } }
Additional resources: Ray cast with layers section of Use of layers in Unity.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4