第二种函数:static function Raycast (origin : Vector3, direction : Vector3, out hitInfo : RaycastHit, distance : float = Mathf.Infinity, layerMask : int = kDefaultRaycastLayers) : bool
origin
The starting point of the ray in world coordinates.
在世界坐标,射线的起始点。
direction
The direction of the ray.
射线的方向。
distance
The length of the ray
射线的长度。
hitInfo
If true is returned, hitInfo will contain more information about where the collider was hit (See Also: RaycastHit).
如果返回true,hitInfo将包含碰到器碰撞的更多信息。
layerMask
A Layer mask that is used to selectively ignore colliders when casting a ray.
只选定Layermask层内的碰撞器,其它层内碰撞器忽略。
此碰撞函数可用于射击游戏里面发射枪弹。
应用例子:
RaycastHit info;
bool hit =Physics.Raycast(枪口的位置 , 摄像机的正前方, out info , 100 ,敌人碰撞层)
{
if(hit)
{
if(info.transform.Tag.CompareTo("enemy")==0)
{