I'm trying to make a worldspace Canvas and interract it with worlds object (3D raycast).
I have a Canvas with a GraphicRaycaster and UI elements with raycast target on. I found some code on internet about UI raycast and I have tested them to simulate a mouse cursor on my Canvas. (I want an hover effect on my buttons, simulate clicks ...).
GraphicRaycaster canvasRaycaster;
Vector2 screenPoint;
void Update()
{
List<RaycastResult> results = new List<RaycastResult>();
PointerEventData eventData = new PointerEventData(EventSystem.current);
eventData.position = screenPoint;
canvasRaycaster.Raycast(eventData, results);
foreach (RaycastResult result in results)
Debug.Log("Hit " + result.gameObject.name);
}
Nothing happens (no debug.log), I've tried with all values between my screen's height and width and between 0 and 1 (x and y) stored in Vector2 screenPoint.