Version: 2017.2

Physics2D.LinecastNonAlloc

Switch to Manual
public static int LinecastNonAlloc (Vector2 start, Vector2 end, RaycastHit2D[] results, int layerMask= DefaultRaycastLayers, float minDepth= -Mathf.Infinity, float maxDepth= Mathf.Infinity);

Parameters

minDepth @param minDepth Включает только объекты с координатой Z (глубиной) выше, чем это значение.
maxDepth @param maxDepth Включает только объекты с координатой Z (глубиной) меньше, чем это значение.
start @param point Точка в пространстве в мировых координатах.
end @param point Точка в пространстве в мировых координатах.
results Returned array of objects that intersect the line.
layerMask @param layerMask Фильтр для обнаружения коллайдеров только на определённых слоях.

Returns

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

Description

Casts a line against colliders in the scene.

BoxCast, концептуально, это как протягивание коробки сквозь сцену в определенном направлении. Любой объект, вступающий в контакт с коробкой, может быть обнаружен и зарегистрирован.

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.

Additionally, this will also detect Collider(s) at the start of the line. In this case the line is starting inside the Collider and doesn't intersect the Collider surface. This means that the collision normal cannot be calculated in which case the collision normal returned is set to the inverse of the line vector being tested. This can easily be detected because such results are always at a RaycastHit2D fraction of zero.

See Also: LayerMask class, RaycastHit2D class, Linecast, LinecastAll, DefaultRaycastLayers, IgnoreRaycastLayer, raycastsHitTriggers.