Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • 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 el-RERS · Aug 05, 2015 at 05:33 AM · guibutton

selecting a button by just hovering the mouse over it... how?

I'm making a menu system that makes it possible to use mouse and controller input at the same time, it's working great until now but I wonder if it's possible to make a button get selected when the mouse pointer is only hovering over it. This is in order to avoid having two buttons that appear to be selected at the same time (According to the Eventsystem object, in reality only one is being selected, the other one is being "highlighted" by the mouse pointer).

I was thinking of something along these lines of this code:

 void Start () 
     {
         eve = GameObject.FindGameObjectWithTag("EventSystem").GetComponent<EventSystem>();
         
     }
 
 
     void Update () 
     {
 
   
         if(eve.IsPointerOverGameObject() && eve.currentSelectedGameObject!= /***highlighted gameobject***/ )
         {
             
         eve.SetSelectedGameObject(/***highlighted gameobject***/);
             
         }
     
     }

The /highlighted gameobject/ thing is the part I don't know how to obtain, is there a way to retrieve the gameobject button that is being highlighted by the mouse pointer?

Thanks in advance.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by voporak5 · Aug 05, 2015 at 05:58 AM

You want void OnMouseOver() or void OnMouseEnter() for entering or void OnMouseExit() for exiting of course

http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseOver.html

just be sure the script that has these methods is attached to the game object that you want to hover over

Comment
Add comment · Show 2 · 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 el-RERS · Aug 05, 2015 at 06:15 AM 0
Share

that's kind of the thing I wanted to avoid, since I didn't want to have to attach a script to every single button in every single menu I have (it is very prone to unwanted errors if I happen to forget one of the buttons), I was thinking something like the script I wrote above so I get a single global script that controls all the selections made by the mouse pointer. Is there a way to retrieve the highlighted button by using the PointEventData class for example? I really have no clue on how to use it. Thanks a lot!

avatar image voporak5 · Aug 05, 2015 at 07:08 AM 0
Share

You would have to do a raycast from your camera in the direction of your cursor by converting the screen space coordinates to real world coordinates. Google raycast to cursor for that. And when the ray collides with the object, run the function that you want

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.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUITexture on/off using GUILayout.Button 0 Answers

Gui Button Image 1 Answer

Set Buttons to Interactable within C# 1 Answer

How to create a GUI button with tooltip and intercept the click event? 0 Answers

What's the easiest way to make a texture button with a hover state? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges