unity3d-光线投射世界空间用户界面

unity3d-光线投射世界空间用户界面,unity3d,raycasting,virtual-reality,daydream,Unity3d,Raycasting,Virtual Reality,Daydream,我需要一些帮助与光线投射与白日梦用户界面。由于只有gameObjects立方体的演示,我想知道我可以处理UI元素。UI元素应该像往常一样做出反应,我的意思是突出显示等等。中的帖子很有帮助,但完全是 我使用DrawRay查看指针实际穿过的位置,效果良好。但是没有创建日志消息 void Update() { Quaternion ori = GvrController.Orientation; Vector3 vector = ori * Vector3.forward

我需要一些帮助与光线投射与白日梦用户界面。由于只有gameObjects立方体的演示,我想知道我可以处理UI元素。UI元素应该像往常一样做出反应,我的意思是突出显示等等。中的帖子很有帮助,但完全是

我使用DrawRay查看指针实际穿过的位置,效果良好。但是没有创建日志消息

 void Update()
  {
      Quaternion ori = GvrController.Orientation;
      Vector3 vector = ori * Vector3.forward;
      Debug.DrawRay(transform.position, vector * 100000, Color.green);
      PointerEventData pointerData = new PointerEventData(null);
      pointerData.position = vector;
      Debug.Log(vector);
      List<RaycastResult> results = new List<RaycastResult>();
      EventSystem.current.RaycastAll(pointerData, results);
      if (results.Count > 0)
      {
          Debug.Log(results[0]);
      }
  }

画布世界空间和按钮被创建为可用且未修改。

在您的案例中,我发现两个问题:

我认为应该使用pointereventdatapointerdata=newpointereventdataeventsystem.current;代替PointerEventData pointerData=新的PointerEventDatanull; 另外PointerEventData.position是一个矢量2而不是矢量3:您应该尝试pointerData.position=new Vector2Screen.width*0.5f,Screen.height*0.5f;
作为旁注,您可以使用graphicRaycaster.RaycastpointerData,结果;如果graphicRaycaster是公共的,您可以将其指定为画布的graphicRaycaster组件。

根据您的问题raycasting world space UI,如果您使用的是google cardbard或daydream,您应该尝试将脚本gvrgraphicphysics raycaster附加到UI画布。

这个有用的方法如何:

Vector3 CurrentRaycastResultWorldPosition = GvrPointerInputModule.Pointer.CurrentRaycastResult.worldPosition;         

谢谢@Kardux的提示。但不幸的是,它不起作用。1.矢量2和屏幕应该如何工作?我不需要屏幕大小,但需要控制器的方向。向量输出是-0.5,0.0,0.9,指针数据。位置是-0.5,0.0-这行吗?2.我将GraphicRaycaster组件添加到父画布,并使用公共GraphicRaycaster GraphicRaycaster,但根本不使用日志条目。。。还有别的想法吗?我需要GUICamera吗?@fmielke我对Vector2(包括屏幕大小)的看法不好:在我的情况下,我总是使用屏幕中间对UI进行光线投射,这样用户只需查看UI即可激活它。通过赋予向量2向量值,你根本不考虑Z值,这就是为什么得到-0.5,0。在你的情况下,我通常会使用物理进行光线投射。光线投射在你的UI所在的鬼墙上,然后使用Camera.WorldToScreenPoint获取屏幕x和y坐标以设置指针data.position。实际上,我只需要光线投射命中信息中的游戏对象行为;如果Physics.RaycastVector3.zero,vector,out hitInfo{Debug.LogHIT a game object;}但仅适用于UI: