Version: 2017.4
public static RaycastHit2D Linecast (Vector2 start, Vector2 end, int layerMask= DefaultRaycastLayers, float minDepth= -Mathf.Infinity, float maxDepth= Mathf.Infinity);

パラメーター

startワールド座標での線の開始地点
endワールド座標での線の終了地点
layerMask特定のレイヤーのコライダーのみを判別するためのフィルター
minDepthこの値以上の Z 座標(深度)を持つオブジェクトのみを含みます。
maxDepthこの値以下の Z 座標(深度)を持つオブジェクトのみを含みます。

戻り値

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

説明

Casts a line segment against colliders in the Scene.

A linecast is an imaginary line between two points in world space. Any object making contact with this line can be detected and reported. This differs from the similar raycast in that raycasting specifies the line using an origin and direction.

この関数は線がシーン上のコライダーと接触したとき RaycastHit2D を返します。layerMask は Linecast するときに特定のレイヤーのみ選択的に接触を検知するために使用します(例えば敵キャラクターの場合のみ検知する、など)。線の向きは開始地点から終了地点とみなされます。その向きにおいて最初に検知されてコライダーのみが報告されます。Z 軸は 2D で衝突を検知するにあたって無関係ですが、minDepthmaxDepth 引数を使用して Z 座標に基づいてオブジェクトをフィルタリングできます。

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

この関数は返された RaycastHit2D 配列にメモリ割り当てを行ないます。LinecastNonAlloc を使用して、そのようなコールを頻繁に行なう必要があればこのオーバーヘッドを回避できます。

さらにこの関数は線の開始地点のコライダーを検知します。この場合線がコライダーの中で開始していてコライダーの表面と交差していません。つまり返された衝突の法線がテストする線のベクトルの反対にセットされた場合、衝突の法線が計算できません。このような結果は RaycastHit2D の 0 地点で得られるため、これを検知するのは容易です。

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


public static int Linecast (Vector2 start, Vector2 end, ContactFilter2D contactFilter, RaycastHit2D[] results);

パラメーター

startワールド座標での線の開始地点
endワールド座標での線の終了地点
resultsThe array to receive results. The size of the array determines the maximum number of results that can be returned.
contactFilterThe contact filter used to filter the results differently, such as by layer mask, Z depth, or normal angle.

戻り値

int Returns the number of results placed in the results array.

説明

Casts a line segment against colliders in the Scene with results filtered by ContactFilter2D.

A linecast is an imaginary line between two points in world space. Any object making contact with this line can be detected and reported. This differs from the similar raycast in that raycasting specifies the line using an origin and direction.

The overloads of this function with the contactFilter parameter, can filter the returned results by the options in ContactFilter2D.

See Also: ContactFilter2D and RaycastHit2D.