Aaron Ge
Aaron Ge

Reputation: 278

OnMouseEnter, OnMouseOver, OnMouseExit.... ect. not working in Unity

Unity had once again left me baffled. When the player's mouse hovers over the UI Image, slot, "Hello" should've been printed out, but it didn't work. I may have just made the most obvious mistake and seem like a total fool, but I have made sure that

  1. That I have a box collider on all my UI Elements
  2. All My Scripts and Box Colliders Are Enabled
  3. That I did not mistype OnMouseEnter()

Sorry to bother you with such a miniscule error, but thank you in advance for helping me!

Code

Unity

Upvotes: 0

Views: 2491

Answers (1)

Allen
Allen

Reputation: 567

For working with Unity 4.6+ UI, include UnityEngine.EventSystem in your script. Add all the IPointer interfaces that you want. Finally, make sure your UI item with the script has either an image or a collider added to it. If you go the collider route, add a physics2draycaster component to your camera.

See the link below:

http://docs.unity3d.com/Manual/SupportedEvents.html

Upvotes: 2

Related Questions