Version: 2021.1

Physics2D.BoxCastNonAlloc

切换到手册
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);

参数

origin 盒体在 2D 空间中的起点。
size 盒体的大小。
angle 盒体的角度(以度为单位)。
direction 表示盒体方向的矢量。
results 用于接收结果的数组。
distance 盒体的最大投射距离。
layerMask 过滤器,用于仅在特定层上检测碰撞体。
minDepth 仅包括 Z 坐标(深度)大于或等于该值的对象。
maxDepth 仅包括 Z 坐标(深度)小于或等于该值的对象。

返回

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

描述

Casts a box into the Scene, returning Colliders that contact with it into the provided results array. Note: This method will be deprecated in a future build and it is recommended to use BoxCast instead.

此函数类似于 BoxCastAll 函数,不同之处在于其结果会返回到提供的数组中。整数返回值是与该盒体交叠的对象数(可能为零),但如果结果数组中没有足够的元素来报告所有这些结果,则不会调整该数组的大小。其意义在于不为这些结果分配内存,因此在经常执行时会提高垃圾回收性能。

The returned RaycastHit2D returns both the point and normal of the contact where the box would touch the Collider. It also returns the centroid where the box would be positioned for it to contact at that point.

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