• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by dxmachina · Jan 20, 2016 at 08:20 PM · guibuttonmouseuser interface

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!!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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]

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to make a Hover event on GUI.Button 6 Answers

Unity UI Button touching from far distance 0 Answers

If mouse is hovering over any GUI element 0 Answers

MouseDown on GUI.button 4 Answers

Specify OnMouseEnter 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges