GetRayIntersection
Cast a 3D ray against the 2D Colliders in the Scene.
Read time 3 minutesLast updated 4 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.Physics2DModule
GetRayIntersection(Ray, float, int)
Cast a 3D ray against the 2D Colliders in the Scene.
public RaycastHit2D GetRayIntersection(Ray ray, float distance, int layerMask = -5)
Parameters
Returns
Type | Description |
|---|---|
| RaycastHit2D | The ray intersection result. |
Remarks
This function acts as a 3D "ray cast" but specifically designed to detect 2D Colliders. It achieved this by projecting the 3D ray into 2D space and then performs the 2D intersection test, ordering the results by the Z direction of the original 3D ray.
GetRayIntersection(Ray, float, RaycastHit2D[], int)
Cast a 3D ray against the 2D Colliders in the Scene.
public int GetRayIntersection(Ray ray, float distance, RaycastHit2D[] results, int layerMask = -5)
Parameters
The 3D ray defining origin and direction to test.
The maximum distance over which to cast the ray.
The array to receive results. The size of the array determines the maximum number of results that can be returned.
The LayerMask filter used to select which layers to detect Colliders for.
Returns
Type | Description |
|---|---|
| int | The number of RaycastHit2D results returned. |
Remarks
This function acts as a 3D "ray cast" but specifically designed to detect 2D Colliders. It achieved this by projecting the 3D ray into 2D space and then performs the 2D intersection test, ordering the results by the Z direction of the original 3D ray.
GetRayIntersection(Ray, float, List<RaycastHit2D>, int)
Cast a 3D ray against the 2D Colliders in the Scene.
public int GetRayIntersection(Ray ray, float distance, List<RaycastHit2D> results, int layerMask = -5)
Parameters
The 3D ray defining origin and direction to test.
The maximum distance over which to cast the ray.
The list to receieve results.
The LayerMask filter used to select which layers to detect Colliders for.
Returns
Type | Description |
|---|---|
| int | The number of RaycastHit2D results returned. |
Remarks
This function acts as a 3D "ray cast" but specifically designed to detect 2D Colliders. It achieved this by projecting the 3D ray into 2D space and then performs the 2D intersection test, ordering the results by the Z direction of the original 3D ray.
GetRayIntersection(Ray, float, int, Allocator)
Cast a 3D ray against the 2D Colliders in the Scene.
public readonly NativeArray<RaycastHit2D> GetRayIntersection(Ray ray, float distance, int layerMask = -5, Allocator allocator = Allocator.Temp)
Parameters
The 3D ray defining origin and direction to test.
The maximum distance over which to cast the ray.
The LayerMask filter used to select which layers to detect Colliders for.
The memory allocator to use for the results. This can only be Allocator.Temp, Allocator.TempJob or Allocator.Persistent.
Returns
Type | Description |
|---|---|
| NativeArray<RaycastHit2D> | The NativeArray that contains the results. This must be disposed of unless it contains no results. |
Remarks
This function acts as a 3D "ray cast" but specifically designed to detect 2D Colliders. It achieved this by projecting the 3D ray into 2D space and then performs the 2D intersection test, ordering the results by the Z direction of the original 3D ray.