Version: 2020.3
言語: 日本語
public static RaycastHit2D[] RaycastAll (Vector2 origin, Vector2 direction, float distance= Mathf.Infinity, int layerMask= DefaultRaycastLayers, float minDepth= -Mathf.Infinity, float maxDepth= Mathf.Infinity);

パラメーター

origin 2D 空間上のレイの原点
direction A vector representing the direction of the ray.
distance The maximum distance over which to cast the ray.
layerMask 特定のレイヤーのコライダーのみを判別するためのフィルター
minDepth この値以上の Z 座標(深度)を持つオブジェクトのみを含みます。
maxDepth この値以下の Z 座標(深度)を持つオブジェクトのみを含みます。

戻り値

RaycastHit2D[] 投げかけた結果が返されます。

説明

Casts a ray against Colliders in the Scene, returning all Colliders that contact with it.

Raycast は例えるならば、空間上のある地点から特定方向へ発射されたセンサーのようなものです。センサーと接触したすべてのオブジェクトは検知され報告されます。

This function is similar to the Raycast function but instead of detecting just the first Collider that is hit, an array of all Colliders along the path of the ray is returned. The Colliders in the array are sorted in order of distance from the origin point. The layerMask can be used to detect objects selectively only on certain layers (this allows you to apply the detection only to enemy characters, for example).

Raycast は視界の範囲の判定、銃弾によりターゲットの当たり判定、さらに多くのゲームシーンで役に立ちます。

Additionally, this will also detect Collider(s) at the start of the ray. In this case, the ray starts inside the Collider and doesn't intersect the Collider surface. This means that the collision normal cannot be calculated, in which case the returned collision normal is set to the inverse of the ray vector being tested. This can easily be detected because such results are always at a RaycastHit2D fraction of zero.

関連項目: LayerMask クラス、RaycastHit2D クラス、RaycastLinecastDefaultRaycastLayersIgnoreRaycastLayerraycastsHitTriggers.