- Home /
In the new UI system is there any way to track where the mouse is when over a button or other UI control?
I've tried a few ideas posted on the forums, but none have worked.
For example - I'd like to create a wide button and have 5 horizontal sections of the button that affect the result of the button press.
I've tried hacking around it by combining 5 different buttons with an image underneath - and while I can get that to work, I'd highly prefer to use a single button if possible.
Thanks!!
Answer by hexagonius · Jan 20, 2016 at 09:19 PM
You should be able to derive from the UIButton. there are several interfaces Unity provides too, maybe there is one like "moving mouse on button"you can extend it with. If it suffices clicking on it, just override the OnClick behaviour. then there is the RectTransformUtility class which would let you transform the mouse coordinates into the button space. divided by 5 it should give you a distinction between the sections.
Answer by dxmachina · Jan 21, 2016 at 11:11 AM
Okay, was able to do this by simply using GetWorldCorners on the RectTransform of the button. Then I compare that to Input.mousePosition.
The first answer here was very helpful: [http://answers.unity3d.com/questions/931778/new-ui-check-for-mouse-hover.html]
Your answer
Follow this Question
Related Questions
Right-click button using GUI class? 3 Answers
Menu button needs to be double clicked. 4 Answers
Disable a GUI while left mouse button is Down? 2 Answers
Button being pressed but an other button gets the effect. 0 Answers
How to detect if mouse over a button 2 Answers