Version: 2020.2

Physics2D.LinecastNonAlloc

切换到手册
public static int LinecastNonAlloc (Vector2 start, Vector2 end, RaycastHit2D[] results, int layerMask= DefaultRaycastLayers, float minDepth= -Mathf.Infinity, float maxDepth= Mathf.Infinity);

参数

minDepth 仅包括 Z 坐标(深度)大于或等于该值的对象。
maxDepth 仅包括 Z 坐标(深度)小于或等于该值的对象。
start 线在世界空间中的起点。
end 线在世界空间中的终点。
results 返回与线条相交的对象的数组。
layerMask 过滤器,用于仅在特定层上检测碰撞体。

返回

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

描述

Casts a line against Colliders in the Scene. Note: This method will be deprecated in a future build and it is recommended to use Linecast instead.

linecast 是世界空间中两点之间的一段假想线。在该过程中,可以检测并报告与光束接触的任何对象。它类似于 raycast,不同之处在于,射线投射使用原点和方向指定线条。

This function is similar to the LinecastAll function except that the results are returned in the supplied array. The integer return value is the number of objects that intersect the line (possibly zero) but the results array will not be resized if it doesn't contain enough elements to report all the results. The significance of this is that no memory is allocated for the results and so garbage collection performance is improved when linecasts are performed frequently. The line is assumed to run from its start point to its end point; Colliders will be placed in the returned array in order of distance from the start of the line.

此外,这还将检测位于线条起点的碰撞体。在这种情况下,线条从碰撞体内部开始,并且不与碰撞体表面交叠。这意味着无法计算碰撞法线,在这种情况下,返回的碰撞法线设置为正在测试的线条向量的倒数。这可轻松检测到,因为此类结果始终是 RaycastHit2D 分数为零。

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

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961