Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
This question was closed Apr 26, 2016 at 10:19 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
4
Question by Chng · Jul 02, 2015 at 03:54 PM · scripting problemuibuttononmouseenter

[SOLVE] OnMouseEnter not working on UI elements

Hey guys!

First time asking here, I'm really new to scripting in C#, so this might be an over sight on my end, but I'm trying to change the alpha value of the image on the Button UI element.

So the results I'm trying to achieve is on start up, the Button is semi transparent, and when you mouse over the button, it will become fully opaque, and once the mouse leave, the button is transparent again.

This is the Script I made

     private Button button;
     public Color color;
     
     void Start()
     {
             button = GetComponent<Button>();
             color.a = .7f;
             button.image.color = color;
             print ("Start");
     }
 
     void OnMouseEnter()
     {
         color.a = 1f;
         button.image.color = color;
         print ("highlight");
     }
     
     void OnMouseExit()
     {
         color.a = 0.7f;
         button.image.color = color;
         print ("Exit");
     }

I've tried adding both a Box Collider and a Box Collider2D but it still doesn't print anything on the console when I mouse over. Any help on the subject would be much appreciated!

Sincerely, Jason

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

  • Sort: 
avatar image
10
Best Answer

Answer by meat5000 · Jul 02, 2015 at 03:54 PM

I do not think it works on UI elements.

It works on Colliders and "GUIElement" which is the name for the GUI system that was used before OnGUI.

The new UI uses Pointer methods which require you to 'implement' callbacks (IPointerEnterHandler etc) in your scripts and make use of the Event System.

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

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 Chng · Jul 02, 2015 at 04:56 PM 0
Share

Thanks for replying! I've manage to succeed using Event Triggers.

I thought GUI and the new UI was the same thing, but guess they are not, thanks for clarifying that!

avatar image meat5000 ♦ · Jul 02, 2015 at 10:09 PM 0
Share

No problem. Click the tick to accept the answer.

avatar image
12

Answer by Chng · Jul 03, 2015 at 07:29 AM

Figured out! Add am Event Trigger component to the button. and add Poiner Enter Event Type. Drag the button that have the script and set the function!

Comment
Add comment · Show 4 · 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 suananki · Jul 13, 2017 at 05:59 AM 1
Share

But there's no method name's OnPointerOver to substitute On$$anonymous$$ouseOver if you want to call every frame while the mouse is over the GUIEliment or Collider,how can you figure out that?

avatar image ransomink suananki · Aug 09, 2017 at 06:22 AM 0
Share

you use OnPointerEnter in place of On$$anonymous$$ouseOver...

avatar image epicpython · Aug 01, 2017 at 02:53 AM 0
Share

Note that you have to change "Runtime only" to "Editor and Runtime" if you want to test it out in the editor.

Other than that, worked perfectly, great advice! :)

avatar image AdmiralThrawn · Nov 10, 2017 at 12:35 AM 0
Share

Totally not transparent how this should work.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

Pressing space calls the wrong function 1 Answer

How to get an array of all Buttons attached to a Panel? 2 Answers

UI Buttons to work continuously when pressed and held for sometime 1 Answer

Is there a way to have 1 Button update the values of variables of a script that is on multiple game objects? 1 Answer

Scripting button functionality inside class with created object's method 1 Answer


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