前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Unity射线检测

Unity射线检测

作者头像
祝你万事顺利
发布2019-05-29 16:01:38
9080
发布2019-05-29 16:01:38
举报
文章被收录于专栏:Unity游戏开发Unity游戏开发

Physics.RayCast方法发射射线,射线碰撞的信息存在RaycastHit中。

代码语言:javascript
复制
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit raycastHit;
        Physics.Raycast(ray,out raycastHit, 1000f);
        navMeshAgent.SetDestination(raycastHit.point);

Camera.main.ScreenPointToRay

Returns a ray going from camera through a screen point. Resulting ray is in world space, starting on the near plane of the camera and going through position's (x,y) pixel coordinates on the screen (position.z is ignored).

Input.mousePosition

The current mouse position in pixel coordinates. (Read Only) The bottom-left of the screen or window is at (0, 0). The top-right of the screen or window is at (Screen.width, Screen.height).

Physics.RayCast:

bool True if the ray intersects with a Collider, otherwise false.

RaycastHit

Structure used to get information back from a raycast. 碰撞的信息存在此对象中

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.05.16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档