CheckSphere(Vector3, float, int, QueryTriggerInteraction)
Returns true if there are any colliders overlapping the sphere defined by position and radius in world coordinates.
Read time 1 minuteLast updated 5 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.PhysicsModule
public static bool CheckSphere(Vector3 position, float radius, int layerMask, QueryTriggerInteraction queryTriggerInteraction)
Parameters
Center of the sphere.
Radius of the sphere.
A Layer mask that is used to selectively filter which colliders are considered when casting a sphere.
Specifies whether this query should hit Triggers.
Returns
Type | Description |
|---|---|
| bool |
Examples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ public float sphereRadius; AudioSource audioSource; void Start() { audioSource = GetComponent<AudioSource>(); } void WarningNoise() { // Play a noise if an object is within the sphere's radius. if (Physics.CheckSphere(transform.position, sphereRadius)) { audioSource.Play(); } }}