Bounds.IntersectRay 相交射线
2015-11-18 01:31
726 查看
转载自:http://game.ceeger.com/Script/Bounds/Bounds.IntersectRay.htmlfunction IntersectRay (ray : Ray) : bool Description描述Does ray intersect this bounding box?射线与这个边界框相交么?C#JavaScript
// 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 : Ray, outdistance : float) : bool Description描述Does ray intersect this bounding box?射线与这个边界框相交么?When IntersectRay returns true distance will be the distance to the ray's origin. 当IntersectRay返回真,距离将是到射线原点的距离。C#JavaScript
// 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"); }
相关文章推荐
- Kinect结合Unity3D引擎开发体感游戏(一)
- Unity3D中脚本的执行顺序和编译顺序
- Unity3D动态对象优化代码分享
- Unity3D获取当前键盘按键及Unity3D鼠标、键盘的基本操作
- Unity3d获取系统时间
- unity3d发布apk在android虚拟机中运行的详细步骤(unity3d导出android apk)
- Unity3D游戏引擎实现在Android中打开WebView的实例
- unity3d调用手机或电脑摄像头
- Unity3d发布IOS9应用时出现中文乱码的解决方法
- 分享一个开源的网络游戏服务器架构—HouHai
- Unity3D插件详细评测及教学下载
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- Unity3D上路_04-基础资源介绍
- Unity3D上路_05-网络相关