Version: 2023.2

PhysicsScene2D.GetRayIntersection

切换到手册
public RaycastHit2D GetRayIntersection (Ray ray, float distance, int layerMask= Physics2D.DefaultRaycastLayers);

参数

ray 定义要测试的原点和方向的 3D 射线。
distance 射线的最大投射距离。
layerMask The LayerMask filter used to select which layers to detect Colliders for.

返回

RaycastHit2D The ray intersection result.

描述

Cast a 3D ray against the 2D Colliders in the Scene.

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.


public int GetRayIntersection (Ray ray, float distance, List<RaycastHit2D> results, int layerMask= Physics2D.DefaultRaycastLayers);

参数

ray 定义要测试的原点和方向的 3D 射线。
distance 射线的最大投射距离。
results The list to receieve results.
layerMask The LayerMask filter used to select which layers to detect Colliders for.

返回

int The number of RaycastHit2D results returned.

描述

Cast a 3D ray against the 2D Colliders in the Scene.

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.


public int GetRayIntersection (Ray ray, float distance, RaycastHit2D[] results, int layerMask= Physics2D.DefaultRaycastLayers);

参数

ray 定义要测试的原点和方向的 3D 射线。
distance 射线的最大投射距离。
results 用于接收结果的数组。该数组的大小决定可返回的结果的最大数量。
layerMask The LayerMask filter used to select which layers to detect Colliders for.

返回

int The number of RaycastHit2D results returned.

描述

Cast a 3D ray against the 2D Colliders in the Scene.

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.