Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by ianbo · Jul 19, 2016 at 03:19 AM · c#textcanvashighlightmouseover

Issues with OnMouseOver() not working

(I know there are many threads about this, but none seem to fix my issue)

I've been trying to get a UI Button component to make another text component change when highlighted.

Even though I have a 2D Rigidbody and I made sure to make it a trigger, I can't get my code to enter the OnMouseOver() event. I don't have a background and my Button is set to "Raycast Target".

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class mouseOverController : MonoBehaviour
 {
     public Text descriptionText;
     public string description;
 
     void Start()
     {
         descriptionText = descriptionText.GetComponent<Text>();
     }
 
     public void OnMouseOver()
     {
         Debug.Log("Here"); //This is never logging
         descriptionText.text = description;
     }
 }

This script is attached to each Button that I want to change my text component.

Any ideas? All suggestions you can come up with are welcome!

Comment
Add comment · Show 1
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 moment_um · Jul 19, 2018 at 11:35 PM 0
Share

did you mean to say made sure NOT to make it a trigger? because in the documentation it specifically says it will not work on triggers unless you have physics.querieshittriggers set to true.

2 Replies

· Add your reply
  • Sort: 
avatar image
10
Best Answer

Answer by CodeElemental · Jul 19, 2016 at 07:44 AM

What you could do is implement the appropriate interfaces IPointerEnterHandler, IPointerExitHandler .

Your adjusted code would need to be something like :

 public class mouseOverController : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
  {
      public Text descriptionText;
      public string description;
  
      void Start()
      {
          descriptionText = descriptionText.GetComponent<Text>();
      }
 
     public void OnPointerEnter(PointerEventData eventData)
     {
         Debug.Log("Here"); //This is never logging
          descriptionText.text = description;
     }
 
     public void OnPointerExit(PointerEventData eventData)
     {
         Debug.Log("Mouse exit");
     }
  }
Comment
Add comment · Show 3 · 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 HorusVision · Mar 08, 2019 at 06:58 PM 0
Share

Thank you! I used this to implement tooltips for UI elements.

avatar image shoopscooper · Nov 13, 2019 at 04:00 AM 0
Share

Been scouring the web for an easy solution for the last 2 hours. Finally something simple and easy. THAN$$anonymous$$ YOU!

avatar image DenisGLabrecque · Dec 16, 2019 at 02:11 AM 0
Share

Thank you! Is there a reason why the documentation for $$anonymous$$onoBehaviour.On$$anonymous$$ouseEnter() doesn't implement the interfaces?

avatar image
4

Answer by moment_um · Jul 19, 2018 at 11:33 PM

  1. Idk why it doesn't mention anywhere that OnMouse***() functions DO NOT work on UI elements, but they don't. You have to either use the EventTrigger component (PointerEnter event) or you can do what codeelemental said and implement the corresponding interfaces.

  2. Also, you are probably looking for OnMouseEnter, as OnMouseOver is called every frame.

  3. Another thought is, it seems you are trying to make a hint text. You might want to try and change the button transition type to animation instead of color, and enable the text object in the "highlighted" animation clip (you must also make the text a child of the button). You could even do a nice smooth expansion of a chat box or something.

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.

Follow this Question

Answers Answers and Comments

198 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Having text be a child to a game object? 2 Answers

Updated with UI text element not correct (same frame) 0 Answers

Weird text field bug? 1 Answer

Damage Text pop-up when enemy is hit 1 Answer

How to link up instantiated text in list to allow buttons to adjust number shown, c# 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