Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

IPointerEnterHandler help

Discussion in 'Scripting' started by CNibbles, Mar 27, 2020.

  1. CNibbles

    CNibbles

    Joined:
    May 11, 2017
    Posts:
    5
    I have a small class to check when the mouse enters a UI image, but it doesn't work. I've tried looking it up, but can't figure it out.


    Class

    Code (CSharp):
    1. public class UIMouseOverable : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler
    2. {
    3.     void Start()
    4.     {
    5.         Debug.Log("It's on");
    6.     }
    7.     public void OnPointerEnter(PointerEventData eventData)
    8.     {
    9.         Debug.Log("Enter");
    10.     }
    11.  
    12.     public void OnPointerExit(PointerEventData eventData)
    13.     {
    14.         Debug.Log("Exit");
    15.     }
    16.  
    17.     public void OnPointerDown(PointerEventData eventData)
    18.     {
    19.         Debug.Log("Down");
    20.     }
    21.  
    22. }
    Picture of what the UI looks like/what is checked
     
    Last edited: Mar 27, 2020
  2. Kobaltic1

    Kobaltic1

    Joined:
    Jan 22, 2015
    Posts:
    151
    Not sure about your code but on you UI you can add an Event Trigger and then select the OnPointerEnter. Next click the + sign. Then add in the object you want and select the script and function to call from that object.

    upload_2020-3-27_21-30-36.png
     
unityunity