Collider.Raycast 光线投射


function Raycast (ray : Ray, out hitInfo : RaycastHit, distance : float) : bool

Parameters参数

  • 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)
  • distance
    The length of the ray
       光线的长度。

Returns

bool - True when the ray intersects any collider, otherwise false.

返回布尔(bool)值,当光线和任何碰撞器相交时,返回true,否则为false。也就是说,当光线碰触到任何碰撞器时返回真,否则返回假。

Description描述

Casts a Ray that ignores all Colliders except this one.

投射一个光线(Ray),它忽略所有碰撞器,除了这个。

Same as above using ray.origin and ray.direction instead of origin and direction.

同上使用 ray.origin 和 ray.direction 而不是origin 和 direction

// pragma below is needed due to a UnityJS issue//下面的代码运行于js#pragma strictfunction Update(){var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);var hit : RaycastHit;if (collider.Raycast (ray, hit, 100.0)) {Debug.DrawLine (ray.origin, hit.point);}}


,