We wanted to do a raycast from an arbitrary position over uGUI objects. As far as we can tell, we seem to need an instance of GraphicRaycaster. As one comes attached to the default Canvas object, we could easily get its reference (let’s call it “raycaster”) and then call raycaster.Raycast(...)
.
Now, Raycast receives two arguments: a PointerEventData
(common event object to all mouse/touch events) and a List
. Currently, the documentation for Raycast does not describe what it does exactly, but we assume that the List of RaycastResults is filled by Raycast itself. From each RaycastResult we could then access the gameObject
it hit (it’s documented here).
But what about PointerEventData
? Isn’t it supposed to come from a pointer event? Here, we have no mouse or touch, and simply want to raycast from an arbitrary position. How should we proceed to create one and set its (screen/world) position? Or is there another way for uGUI raycasts altogether?