Bounds.IntersectRay 相交射线

转载自:http://game.ceeger.com/Script/Bounds/Bounds.IntersectRay.html

function IntersectRay (ray : Ray) : bool 

Description描述

Does ray intersect this bounding box?

射线与这个边界框相交么?

// Creates a ray that points from the origin to the infinity among the z Axis.
// And prints if the transform touched the ray.
//沿着z轴,从原点到无限远,创建一条射线
//并且如果变换碰到射线,打印消息
var ra : Ray = new Ray (Vector3.zero, Vector3.forward);

function Update () {
	// Color ra in the scene editor.
	//在场景编辑器,给射线一个颜色
	Debug.DrawRay (Vector3.zero, Vector3.forward * 999, Color.green);
	var bounds : Bounds = transform.collider.bounds;
	if (bounds.IntersectRay (ra))
		Debug.Log("Touched the ray");
}

• function IntersectRay (ray : Rayout distance : float) : bool 

Description描述

Does ray intersect this bounding box?

射线与这个边界框相交么?

When IntersectRay returns true distance will be the distance to the ray's origin. 

当IntersectRay返回真,距离将是到射线原点的距离。

// Creates a ray that points from the origin to 10 units among the z Axis.
// And prints if the transform touched the ray.
//沿着z轴,从原点到10个单位之间,创建一条射线
//并且如果变换碰到射线,打印消息
var ra : Ray = new Ray (Vector3.zero, Vector3.forward);
var t : float = 10.0;

function Update () {
	// Color ra in the scene editor.
	//在场景编辑器,给射线一个颜色
	Debug.DrawRay (Vector3.zero, Vector3.forward * 10, Color.green);
	var bounds : Bounds = transform.collider.bounds;
	if (bounds.IntersectRay (ra, t))
		Debug.Log("Touched the ray");
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值