public static Collider2D OverlapBox (Vector2 point, Vector2 size, float angle, int layerMask= DefaultRaycastLayers, float minDepth= -Mathf.Infinity, float maxDepth= Mathf.Infinity);

Parameters

pointThe center of the box.
size盒体的大小。
angleThe angle of the box.
layerMask筛选器,用于检查仅在指定层上的对象。
minDepth仅包括 Z 坐标(深度)大于该值的对象。
maxDepth仅包括 Z 坐标(深度)小于该值的对象。

Returns

Collider2D 与该盒体重叠的碰撞体。

Description

检查某碰撞体是否位于一个盒形区域内。

盒体由其在世界空间中的中心坐标及其大小定义。可选的 layerMask 可让测试仅检查特定层上的对象。

虽然 Z 轴与 2D 中的渲染或碰撞无关,但您可以使用 minDepthmaxDepth 参数根据其 Z 轴坐标筛选对象。如果有多个碰撞体位于该盒体内,则返回 Z 坐标值最小的碰撞体。如果该盒体内没有任何碰撞体,则返回 Null。

另请参阅:OverlapBoxAllOverlapBoxNonAlloc


public static int OverlapBox (Vector2 point, Vector2 size, float angle, ContactFilter2D contactFilter, Collider2D[] results);

Parameters

pointThe center of the box.
size盒体的大小。
angleThe angle of the box.
contactFilter接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度。注意,法线角度不用于重叠测试。
results用于接收结果的数组。该数组的大小决定可返回的结果的最大数量。

Returns

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

Description

检查某碰撞体是否位于一个盒形区域内。

盒体由其在世界空间中的中心坐标及其大小定义。

该函数返回找到的碰撞体数,并将这些碰撞体放入 results 数组。也可以通过 contactFilter 对结果进行过滤。注意,按法线角筛选不适用于重叠函数。


Parameters

pointThe center of the box.
size盒体的大小。
angleThe angle of the box.
contactFilter接触筛选器,用于以不同方式筛选结果,例如按层遮罩、Z 深度。注意,法线角度不用于重叠测试。
resultsThe list to receive results.

Returns

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

Description

Checks if a Collider falls within a box area.

盒体由其在世界空间中的中心坐标及其大小定义。

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.

Note that filtering by normal angle is not available for overlap functions.