public static RaycastHit2D BoxCast (Vector2 origin, Vector2 size, float angle, Vector2 direction, float distance= Mathf.Infinity, int layerMask= Physics2D.AllLayers, float minDepth= -Mathf.Infinity, float maxDepth= Mathf.Infinity);

Parameters

origin盒体在 2D 空间中的起点。
size盒体的大小。
angle盒体的角度(以度为单位)。
directionA vector representing the direction of the box.
distanceThe maximum distance over which to cast the box.
layerMask过滤器,用于仅在特定层上检测碰撞体。
minDepth仅包括 Z 坐标(深度)大于或等于该值的对象。
maxDepth仅包括 Z 坐标(深度)小于或等于该值的对象。

Returns

RaycastHit2D 返回的投射数量。

Description

Casts a box against colliders in the Scene, returning the first collider to contact with it.

A BoxCast is conceptually like dragging a box through the Scene in a particular direction. Any object making contact with the box can be detected and reported.

函数返回一个 RaycastHit2D 对象,该对象引用了盒体命中的碰撞体 (如果未命中任何对象,则结果的碰撞体属性将为 NULL)。layerMask 可用于 仅在特定层上有选择地检测对象 (例如,这让您能够仅将检测应用于敌人角色)。

返回的 RaycastHit2D 将返回盒体将与碰撞体接触的 点和法线。此外,它还返回当盒体接触该点时 盒体的质心。

BoxCast 有一个 size 选项。该选项定义了盒体的大小。发射的盒体 将穿过世界。盒体越大,命中的 GameObject 越多。

BoxCast 还有一个 angle 选项。发射的穿过游戏中元素的盒体 可以旋转。这意味着,可能很难观察到 BoxCast 与 GameObject 之间的碰撞。

BoxCast.direction 变量用于确定盒体在游戏中的移动方式。这是一个控制水平和垂直方向的 2D 变量。

Distance 控制盒体从 origin 开始行进的距离。它可能会与 多个或 0 个 Collider 进行交互。在这些情况下,最接近的 Collider2D 提供 在 RaycastHit2D 变量中设置的值。如果未命中任何 Collider2D,则返回 NULL。

另请参阅:LayerMask 类、RaycastHit2D 类、BoxCastAllBoxCastNonAllocDefaultRaycastLayersIgnoreRaycastLayerraycastsHitTriggers


public static int BoxCast (Vector2 origin, Vector2 size, float angle, Vector2 direction, ContactFilter2D contactFilter, RaycastHit2D[] results, float distance= Mathf.Infinity);

Parameters

origin盒体在 2D 空间中的起点。
size盒体的大小。
angle盒体的角度(以度为单位)。
directionA vector representing the direction of the box.
distanceThe maximum distance over which to cast the box.
results用于接收结果的数组。该数组的大小决定可返回的结果的最大数量。
contactFilter接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度或法线角度。

Returns

int 返回放置在 results 数组中的结果数。

Description

Casts a box against the Colliders in the Scene and returns all Colliders that are in contact with it.

A BoxCast is conceptually like dragging a box through the Scene in a particular direction. Any Collider making contact with the box can be detected and reported.

该函数返回找到的接触点数,并将这些接触点放入 results 数组。也可以通过 contactFilter 对结果进行过滤。

另请参阅:ContactFilter2DRaycastHit2D


Parameters

origin盒体在 2D 空间中的起点。
size盒体的大小。
angle盒体的角度(以度为单位)。
directionA vector representing the direction of the box.
contactFilter接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度或法线角度。
resultsThe list to receive results.
distanceThe maximum distance over which to cast the box.

Returns

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

Description

Casts a box against the Colliders in the Scene and returns all Colliders that are in contact with it.

A BoxCast is conceptually like dragging a box through the Scene in a particular direction. Any Collider making contact with the box can be detected and reported.

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.

另请参阅:ContactFilter2DRaycastHit2D