Unity3D射线检测控制转向

Unity3D射线检测控制转向,使用Ray射线检测鼠标的位置信息,角色transform方向转向该位置。

//控制转向
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;//碰撞信息,用来获取从raycast函数中得到的信息反馈的结构
        if (Physics.Raycast(ray, out hitInfo, 200, groundLayerIndex))//检测射线,控制转向
        {
            Vector3 target = hitInfo.point;
            target.y = transform.position.y;
            transform.LookAt(target);
        }

你可能感兴趣的:(Unity3D)