What I need is to find out is the coordinates of touch relative to that UI Element. However as the event is type of Touch and not pc.Touch, I just can’t get it.
Is there a smart way of doing this, without calculating it from screen coordinates?
Unfortunately the event.changedTouches[0].target is the application-canvas, not the UIElement. Hence I get exactly the touch.clientX and touch.clientY, when I do the conversion.
Independent of which element I attach the script to, target is always the application-canvas. I wonder what I am doing wrong.
The “RightPlane” element has the script attached to it. However it seems like coordinates are relative to the “UserInterface” screen and not “RightPlane” element.
I implemented a work-around by calculating the coordinate using the element’s position relative to the screen. However I’m looking if there is a more elegant solution
The Element touch events (or any other input events) do not return Element component coordinates. If you want to get the Element that was touched simply get it from event.element.
What I was looking for is, to get the local coordinates of touch relative to the Element initiated the touch. I can do it by using coordinates of the Element component and calculate it from the screen coordinates of the Touch (such as the example above). But I was looking if there is a more elegant solution
I see - there is no built-in function to do that but you should be able to do it by using the Element’s canvasCorners property which contains the 4 corners of the element in canvas space.
The target in that case refers to HTML elements. The Element components do not exist in HTML they are just regular meshes rendered in WebGL so that function doesn’t apply.