Physics2D.LinecastAll
static function LinecastAll(start: Vector2, end: Vector2, layerMask: int = DefaultRaycastLayers, minDepth: float = -Mathf.Infinity, maxDepth: float = Mathf.Infinity): RaycastHit2D[];
static RaycastHit2D[] LinecastAll(Vector2 start, Vector2 end, int layerMask = DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity);
static def LinecastAll(start as Vector2, end as Vector2, layerMask as int = DefaultRaycastLayers, minDepth as float = -Mathf.Infinity, maxDepth as float = Mathf.Infinity) as RaycastHit2D[]
Parameters

start The start point of the line in world space.
end The end point of the line in world space.
layerMask Filter to detect Colliders only on certain layers.
minDepth Only include objects with a Z coordinate (depth) greater than this value.
maxDepth Only include objects with a Z coordinate (depth) less than this value.
Description

Casts a line against colliders in the scene.

A linecast is an imaginary line between two points in world space. Any object making contact with the beam can be detected and reported.

This function is similar to the Linecast function except that all colliders that are in contact with the line are reported. 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.

Linecasts are useful for determining lines of sight, targets hit by gunfire and for many other purposes in gameplay.

Note that this function will allocate memory for the returned RaycastHit2D array. You can use LinecastNonAlloc to avoid this overhead if you need to make linecasts frequently.

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::ref:: class, RaycastHit2D::ref:: class, Linecast, LinecastNonAlloc, defaultRaycastLayers, ignoreRaycastLayer, raycastsHitTriggers.