Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Example how programming with EventSystem ?

Discussion in 'UGUI & TextMesh Pro' started by Djfeeler, Jun 6, 2015.

  1. Djfeeler

    Djfeeler

    Joined:
    Oct 11, 2014
    Posts:
    17
    Hello,

    Programming with the EventSystem and UI is somewhat vague. Do you have any sample code to detect if the mouse is over a button, an image when this one appears?

    Thanks in advance.
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    Check in the docs / source for the IPointerEventHandlers (e.g. IPointerEnterhandler, IPointerExitHandler and so on)
    You attach these interfaces to your scripts and implement their functions in order to take advantage of the new EventSystem.
    http://docs.unity3d.com/ScriptReference/EventSystems.IPointerEnterHandler.html

    The docs are a bit light but if you search in the UI forums you will see many good examples for these.

    Above all, don't use the EventTrigger component unless you know what you are doing as it is very weighty and not performant.
    Or you can pick up a good book which has an entire chapter on the UI event system :D
     
  3. wolfpack4417

    wolfpack4417

    Joined:
    Jul 5, 2014
    Posts:
    8
    Hey I actually just started trying to learn the EventSystem stuff yesterday, and this video helped me understand it a little better.



    Hope this helps some.

    There was also a good post about overriding the methods like OnSelect and OnDeselect on Unity Answers somewhere that helped me too. I'm not on my home computer or I would try to find it for you in my history.
     
    Trisibo likes this.