0

我需要一些有关使用 Daydream 进行光线投射 UI 的帮助。由于只有游戏对象(立方体)的演示,我想知道我可以处理 UI 元素。UI 元素应该像往常一样做出反应,我的意思是突出显示等等。如何在 WorldSpace UI 中使用 Graphic Raycaster中的帖子?很有帮助,但完全。

我使用 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]);
      }
  }

画布(世界空间)和按钮被创建为有用的而不是修改的。

4

3 回答 3

0

在您的情况下,我看到两个问题:

  • 我认为你应该使用PointerEventData pointerData = new PointerEventData(EventSystem.current);insted ofPointerEventData pointerData = new PointerEventData(null);
  • 也是PointerEventData.positionVector2不是Vector3:您应该尝试pointerData.position = new Vector2(Screen.width * 0.5f, Screen.height * 0.5f);

作为旁注,您可以在 graphicsRaycaster 是公共的地方使用,并将其分配给graphicRaycaster.Raycast(pointerData, results);CanvasGraphicRaycaster组件。

于 2016-11-02T09:24:21.143 回答
0

这个有用的方法怎么样:

Vector3 CurrentRaycastResultWorldPosition = GvrPointerInputModule.Pointer.CurrentRaycastResult.worldPosition;         
于 2018-03-18T23:27:02.177 回答
-1

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

于 2017-10-23T08:57:08.393 回答