- Home /
OnMouseHover on UI
So I want to change my cursor sprite depending on what element I am over.
when dealing with non-UI I use raycasting to determine the cursor, this however does not seem to work with UI elements?
So instead I have tried to implement IPointerHandlers, but these only covers OnEnter and OnExit events, no OnHover(Checking each frame if the cursor is above the object).
These however are extremely hard to work with, since my UI can be SetActive using both Input.GetKeys and OnClicks. Furthermore multiple UIs can be displayed simultaneously, making a simple bool fix
insufficient.
Is there a smarter way?
Answer by HappiiGamer · Oct 14, 2019 at 03:01 PM
In this case I would have a singleton class for Pointer that tracks which UI element it is on and has an Update() that checks if it's still hovering over an Active GO. And, have an MonoBehaviour that registers and unregisters the UI-elements to the Pointer class during OnEnable, OnDisable, OnEnter, OnExit.
If more than one UI-Element overlap, I would have a priority value to track which one should get the hover.
I guess it has to be done this way then. Was hoping for a more elegant solution
Your answer
Follow this Question
Related Questions
UI OnMouseOver for specific objects 0 Answers
Keep cursor enabled 2 Answers
On Pointer Enter for semi-transparent UI? 2 Answers
Help with an upgrade tower system 0 Answers
How do I get OnMouseOver to work again ? 0 Answers