Version: 2019.3
public static int BoxCastNonAlloc (Vector2 origin, Vector2 size, float angle, Vector2 direction, RaycastHit2D[] results, float distance= Mathf.Infinity, int layerMask= DefaultRaycastLayers, float minDepth= -Mathf.Infinity, float maxDepth= Mathf.Infinity);

パラメーター

originThe point in 2D space where the box originates.
sizeThe size of the box.
angleThe angle of the box (in degrees).
directionA vector representing the direction of the box.
results結果を受け取る配列
distanceThe maximum distance over which to cast the box.
layerMask特定のレイヤーのコライダーのみを判別するためのフィルター
minDepthこの値以上の Z 座標(深度)を持つオブジェクトのみを含みます。
maxDepthこの値以下の Z 座標(深度)を持つオブジェクトのみを含みます。

戻り値

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

説明

Casts a box into the Scene, returning colliders that contact with it into the provided results array.

この関数は結果が配列に返されること以外は BoxCastAll 関数と同様です。返される int 値は円形と交わるオブジェクトの数です( 0 の可能性もあります)が、オブジェクトの数が配列よりも多くとも配列の長さが変わることはありません。この仕様について重要なのは、この結果からメモリ割り当てが行われないため、頻繁に実行された場合にガベージコレクションのパフォーマンスが向上するということです。

返された RaycastHit2D はボックスがコライダーに触れる接点の座標と法線の両方を返します。また、その時点でボックスが接触するために位置している場所の重心も返します。

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