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 /
avatar image
0
Question by tormentoarmagedoom · Mar 28, 2018 at 02:19 PM · guibuttonmouseoveronmouseover

OnMouseOver not working.. ?

I just want to know when the mouse is over some buttons, to expand a window with some info text.

Is just simple, I have some canvas with empty objects full of texts, buttons, panels etc... some of this buttons have attached a script with this code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.EventSystems;
 using UnityEngine.UI;
 
 public class GestorUpgrades : MonoBehaviour {
 
     public GameObject PantalletaCost;
     
     void OnMouseEnter()
     {
         Debug.Log("Enter " + gameObject.name);            
     }
 
     void OnMouseOver()
     {
         Debug.Log("Over " + gameObject.name);            
     }
 }
 

But nothing happens when mouse is over or enter them. The buttons and all the canvas hicheracy is NOT in "Ignore Raycast Layer", and i dont know why this is happenning.. :(

Some sugestion? Thaanks!


Update


Hello Legend_Bacon!

Thanks for answer, i researched a little and came up with this solution.

By Inspector: Adding a EventTriger component to the button, add a "Point enter" and a "Point click" and attach the same gameobject with a script with 1 futction for each event.

      public void TheNameIWant1()
      {
          Debug.Log("Enter " + gameObject.name);            
      }
  
      public void TheNameIWant2()
      {
          Debug.Log("Clicked" + gameObject.name);            
      }

Thaanks!

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 Captain_Pineapple · Mar 28, 2018 at 04:14 PM 0
Share

Do you have an event system in your scene?

2 Replies

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

Answer by Legend_Bacon · Mar 28, 2018 at 04:19 PM

Hello there,

As far as I can remember, OnMouseEnter() and OnMouseOver() only work on (old) GUI elements and objects that have a Collider component.

If you want the (new) UI to pick up these events, you need to select your button and add an "event trigger" component. Then, you can add an PointerEnter Event to it, and assign it functions to call just like with a button's OnClick().


Hope that helps!

Cheers,

~LegendBacon

Comment
Add comment · Show 1 · 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 tormentoarmagedoom · Mar 29, 2018 at 07:40 AM 0
Share

Extended Question

avatar image
1

Answer by Hellium · Mar 29, 2018 at 07:53 AM

Make your class implement the UnityEngine.EventSystems.IPointerEnterHandler interface and remove the override keyword of the OnPointerEnter function.

 public class GestorUpgrades : MonoBehaviour : UnityEngine.EventSystems.IPointerEnterHandler {
     public void OnPointerEnter(PointerEventData data)
      {
          Debug.Log("OnPointerEnter called.");
      }
 }

The data parameter is an object containing the information sent by the EventSystem when the latter detected that the pointer entered your object.

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

151 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

Related Questions

How to detect Mouse over gui and guilayout elements? 4 Answers

OnMouseOver() OnMouseDown() button raycast help 1 Answer

Button then instanitates gameobject 1 Answer

TheWebExpert says: My GUI Button is not showing up on Camera Preview 2 Answers

GUI Button Animation Cue 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