Version: 2019.1
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.

This function returns a RaycastHit2D object when the line contacts a Collider in the Scene. 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). The direction of the line is assumed to extend from the start point to the end point. Only the first collider encountered in that direction will be reported. Although the Z axis is not relevant for rendering or collisions in 2D, you can use the minDepth and maxDepth parameters to filter objects based on their Z coordinate.

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

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

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

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


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

パラメーター

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

戻り値

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.


パラメーター

startワールド座標での線の開始地点
endワールド座標での線の終了地点
contactFilterThe contact filter used to filter the results differently, such as by layer mask, Z depth, or normal angle.
resultsThe list to receive results.

戻り値

void Returns the number of results placed in the results list.

説明

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 Collider 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 integer return value is the number of results written into the results list. The results list will be resized if it doesn't contain enough elements to report all the results. This prevents memory from being allocated for results when the results list does not need to be resized, and improves garbage collection performance when the query is performed frequently.

The results can also be filtered by the contactFilter.

See Also: ContactFilter2D and RaycastHit2D.