Home Forums Game Integration Best way to trigger not 3D Objects Reply To: Best way to trigger not 3D Objects

#9345
Francesco Alotto
Participant

Thank you for the fast answer…

My objective is to trigger an UI Button contained into a Canvas.
In my code I’ve:
cursor.transform.position = new Vector2(smoothedpoint.x,smoothedpoint.y);

Where cursor is an image that give information about the points where the user is looking.

If the cursor stay over a button for more than 2 seconds, I want to trigger the button action.

I’ve tried to use Raycast on void Update() function:
`PointerEventData pointerData = new PointerEventData(EventSystem.current);
pointerData.position = position;
List<RaycastResult> results = new List<RaycastResult>();

EventSystem.current.RaycastAll(pointerData, results);
print(results[0].ToString());`

But I don’t know how to achieve the timebased event. Using the mouse cursor, I’ve used the IPointerEnterHandler, IPointerExitHandler to set a boolean value to start the timer.

Could you please help?

I think that this solutions could be useful to a lot of users,

Thank you,

Francesco