Search Unity

Controller Interaction with UI

Discussion in 'Daydream' started by fmielke, Oct 31, 2016.

  1. fmielke

    fmielke

    Joined:
    Oct 17, 2016
    Posts:
    35
    Is there a help/script which shows me how to interact with the controller and UI elements? In the controller demo is only the the Physics Raycaster with game objects used.

    I think I have to use the Graphics Raycaster, but how?

    At the moment I was able to use the DrawRay to confirm whether the controller goes trough the button. And yes, it does. I expected a log entry while moving the controller over the button and his collider (do i actually need a collider?).

    Code (CSharp):
    1.     void Update()
    2.     {
    3.         Quaternion ori = GvrController.Orientation;
    4.         Vector3 vector = ori * Vector3.forward;
    5.         Debug.DrawRay(transform.position, vector * 100000, Color.green);
    6.  
    7.         PointerEventData pointerData = new PointerEventData(EventSystem.current);
    8.         pointerData.position = vector;
    9.  
    10.         List<RaycastResult> results = new List<RaycastResult>();
    11.         EventSystem.current.RaycastAll(pointerData, results);
    12.         if (results.Count > 0)
    13.         {
    14.             Debug.Log(results[0]);
    15.         }
    16.     }
    Thank you!