Search code examples
unity-game-engineaugmented-realityhololensmrtk

How to get coordinates of click on rawImage in Unity using Hololens?


So right now I have a this hierarchy: CubeCanvasRawImage

And I want to get the coordinates of my click on the rawimage, but I dont know where to start right now.

  1. In the HoloToolkit is an GazeManager, where the raycast is performed and there is the property HitPosition. So by using GazeManager.Instance.HitPosition I should get the click position in world. But how do I get from this to the coordinates on the Canvas?
  2. I can trigger OnInputClicked(InputClickedEventData eventData) if I use IInputClickHandler. But from the eventData I wont get Information about the click.
  3. I found this but cant transfer it into my needs. Because his eventData has more options.
  4. I guess there wont be a difference to get the click from the rawimage, or the canvas or the cube, because they have all the same size.

Solution

  • Maybe what you need is to change your approach, I can see some solutions for this.

    1. Change your Canvas from Overlay to World Space and Raycast the click to get a normal position, not Canvas position.

    2. If you have Canvas in Overlay, I think that Input.mousePosition is directly proportional to RectTransform.position, so there is your position.

    For both, you can use IPointerClickHandler to detect the click on any UI element.