Physics.Linecast 线性投射

static function Linecast (start : Vector3, end : Vector3, layerMask : int = kDefaultRaycastLayers) : bool

Description描述

Returns true if there is any collider intersecting the line between start and end.

从开始位置到结束位置做一个光线投射,如果与碰撞体交互,返回真。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Transform target;
	void Update() {
		if (!Physics.Linecast(transform.position, target.position))
			ProcessData.AndDoSomeCalculations();

	}
}
var target : Transform;
	function Update () {
		if (!Physics.Linecast (transform.position, target.position)) {
			ProcessData.AndDoSomeCalculations();
	}
}

Layer mask is used to selectively ignore colliders when casting a ray.

可以根据Layer mask层的不同来忽略碰撞体。

• static function Linecast (start : Vector3, end : Vector3, out hitInfo : RaycastHit, layerMask : int = kDefaultRaycastLayers) : bool

Description描述

Returns true if there is any collider intersecting the line between start and end.

从开始位置到结束位置做一个光线投射,如果与碰撞体交互,返回真。

If true is returned, hitInfo will contain more information about where the collider was hit (See Also: RaycastHit). Layer mask is used to selectively ignore colliders when casting a ray.

如果交互到碰撞体,光线投射返回一个RaycastHit结构体信息。可以根据Layer mask层的不同来忽略碰撞体。

Page last updated: 2011-4-9