文档

Unity Engine

Unity Engine

CheckSphere(Vector3, float, int, QueryTriggerInteraction)

Returns true if there are any colliders overlapping the sphere defined by position and radius in world coordinates.
阅读时间1 分钟最后更新于 1 个月前

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.PhysicsModule
public static bool CheckSphere(Vector3 position, float radius, int layerMask, QueryTriggerInteraction queryTriggerInteraction)

Parameters

position

Center of the sphere.

radius

Radius of the sphere.

layerMask

A Layer mask that is used to selectively filter which colliders are considered when casting a sphere.

queryTriggerInteraction

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(); } }}