Version: 2020.2
言語: 日本語
public static Collider[] OverlapSphere (Vector3 position, float radius, int layerMask= AllLayers, QueryTriggerInteraction queryTriggerInteraction= QueryTriggerInteraction.UseGlobal);

パラメーター

position 球形の中心
radius 球形の半径
layerMask A Layer mask defines which layers of colliders to include in the query.
queryTriggerInteraction トリガーに設定されているものも検索対象にするか

戻り値

Collider[] 球体の内部や触れたすべてのコライダーの配列を取得します

説明

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.