美文网首页
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射线检测

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