Version: 2023.2
언어: 한국어
public static Collider[] OverlapSphere (Vector3 position, float radius, int layerMask= AllLayers, QueryTriggerInteraction queryTriggerInteraction= QueryTriggerInteraction.UseGlobal);

파라미터

position Center of the sphere.
radius Radius of the sphere.
layerMask A Layer mask defines which layers of colliders to include in the query.
queryTriggerInteraction Specifies whether this query should hit Triggers.

반환

Collider[] Returns an array with all colliders touching or inside the sphere.

설명

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.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961