美文网首页
Unity射线检测

Unity射线检测

作者: 祝你万事顺利 | 来源:发表于2019-05-16 14:33 被阅读0次

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

        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.
碰撞的信息存在此对象中

相关文章

  • 射线检测-unity

    与最近物体碰撞取得位置: 与指定层的物体碰撞: 另外collider相当于游戏物体了

  • Unity射线检测

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

  • Unity Physics.Raycast

    参考Unity - 射线检测[https://www.cnblogs.com/SouthBegonia/p/117...

  • API

    Plane.Raycast Plane 的介绍参考例子 Unity 之 plane.Raycast 射线检测 拷贝...

  • Unity 基础 - 射线

    Unity 中虚拟射线能够检测所碰撞到物体,使用 Physics 类的 Raycast 方法实现色心啊碰撞检测功能。

  • Unity_拖拽|全方位拖拽物体攻略

    Unity中UGUI控件和3D物体拖拽实现 基本原理 Unity拖拽的基本原理:射线检测,鼠标位置增量转换为统一空...

  • unity 射线检测与对象池

    真正学懂一个知识的时候是要传授给别人这个知识的时候让对方也能轻而易举的理解。 遇到需要频繁加载和销毁的游戏对象(例...

  • 今晚8点直播 | Unity中射线检测详解

    洪流学堂,让你快人几步。 今晚8点,带你搞清楚Unity中的射线检测。直播地点:QQ群 492325637 如果无...

  • Unity 射线

    1,摄像机射线: 2, 物体发射射线: 3, 点击发出射线:

  • Unity射线

    射线 与现实中激光手电(激光笔)类似,射线的两个要素:原点和方向。unity引擎引入了这种机制,可以通过代码在场景...

网友评论

      本文标题:Unity射线检测

      本文链接:https://www.haomeiwen.com/subject/oqkiaqtx.html