start | @param point Точка в пространстве в мировых координатах. |
end | @param point Точка в пространстве в мировых координатах. |
layerMask | @param layerMask Фильтр для обнаружения коллайдеров только на определённых слоях. |
minDepth | @param minDepth Включает только объекты с координатой Z (глубиной) выше, чем это значение. |
maxDepth | @param maxDepth Включает только объекты с координатой Z (глубиной) меньше, чем это значение. |
RaycastHit2D The cast results returned.
Casts a line against colliders in the scene.
BoxCast, концептуально, это как протягивание коробки сквозь сцену в определенном направлении. Любой объект, вступающий в контакт с коробкой, может быть обнаружен и зарегистрирован.
This function returns a RaycastHit2D object when the line contacts a Collider in the scene. The layerMask can be used to detect objects selectively only on certain layers (this allows you to apply the detection only to enemy characters, for example). The direction of the line is assumed to extend from the start point to the end point. Only the first collider encountered in that direction will be reported. Although the Z axis is not relevant for rendering or collisions in 2D, you can use the minDepth and maxDepth parameters to filter objects based on their Z coordinate.
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 object. 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 class, RaycastHit2D class, LinecastAll, LinecastNonAlloc, DefaultRaycastLayers, IgnoreRaycastLayer, raycastsHitTriggers.