public static bool RayCast(Vector3 origin, Vector3 direction, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static bool Raycast(Vector3 origin, Vector3 direction, out RaycastHit hitInfo, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static bool Raycast(Ray ray, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
public static bool Raycast(Ray ray, out RaycastHit hitInfo, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
Parameters 參數
origin The starting point of the ray in world coordinates. 在世界坐標,射線的起始點。 direction The direction of the ray. 射線的方向。 distance The length of the ray. 射線的長度。 layermask A Layer mask that is used to selectively ignore colliders when casting a ray. 投射射線,選擇投射的層蒙版。 queryTriggerInteraction Specifies whether this query should hit Triggers. 指定是否查詢碰到觸發器。 ray The starting point and direction of the ray. 射線的起點和方向 hitInfo If true is returned, hitInfo will contain more information about where the collider was hit (See Also: RaycastHit). hitInfo將包含碰到器碰撞的更多信息。
RaycastHit 射線投射碰撞信息
Variables 變量 barycentricCoordinate The barycentric coordinate of the triangle we hit. 碰到的三角形的重心坐標。 collider The Collider that was hit. 碰到的碰撞器。 distance The distance from the ray’s origin to the impact point. 從射線的原點到觸碰點的距離。 lightmapCoord The uv lightmap coordinate at the impact point. 在觸碰點的UV光照貼圖的坐標。 normal The normal of the surface the ray hit. 射線觸碰表面的法線。 point The impact point in world space where the ray hit the collider. 在世界坐標空間,射線碰到碰撞器的接觸點。 rigidbody The Rigidbody of the collider that was hit. If the collider is not attached to a rigidbody then it is null. 碰到的該碰撞器上的剛體。如果碰撞器上沒有附加剛體,那么返回null。 textureCoord The uv texture coordinate at the impact point. 在觸碰點的UV紋理坐標。 textureCoord2 The secondary uv texture coordinate at the impact point. 在接觸點處的第二套UV紋理坐標。 transform The Transform of the rigidbody or collider that was hit. 碰到的該剛體或碰撞器的變換。 triangleIndex The index of the triangle that was hit. 碰到的三角形的索引。
Returns 返回
bool True when the ray intersects any collider, otherwise false. 當光線投射與任何碰撞器交叉時為真,否則為假。