Collider.Raycast 光线投射

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

Parameters参数

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 strict



function 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);

	}

}
Page last updated: 2010-12-12