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. Dismiss Notice

onHighlighted (Selected) events

Discussion in 'UGUI & TextMesh Pro' started by Frooxius, Oct 10, 2014.

  1. Frooxius

    Frooxius

    Joined:
    Aug 15, 2012
    Posts:
    57
    Hello,

    I've been playing out with the new UI system (which is great by the way!), but there's one thing that I'm missing and can't find much about: The UI elements sending "OnHighlighted" (or Selected) event, whenever I hover above them, that I could hook up the same way as I do "onValueChanged" or "onClicked".

    I've been thinking about using the custom highlight/press animation on the elements and triggering a function on my script from that will fire the events, but I find that a bit ugly way to do it.

    Or is there something I'm missing?
     
  2. bgs

    bgs

    Joined:
    Jan 14, 2014
    Posts:
    12
    You can make a script that implements the IPointerEnterHandler and ISelectHandler interfaces and do whatever logic in there.


    Code (CSharp):
    1. public class HoverStateScript : MonoBehaviour, IPointerEnterHandler, ISelectHandler
    2. {
    3.     public void OnPointerEnter(PointerEventData eventData)
    4.     {
    5.         Debug.Log("Hovered");
    6.     }
    7.  
    8.     public void OnSelect(BaseEventData eventData)
    9.     {
    10.         Debug.Log("Hovered");
    11.     }
    12. }
     
    Frooxius and BonyYousuf like this.
  3. Frooxius

    Frooxius

    Joined:
    Aug 15, 2012
    Posts:
    57
    Thank you very much, I'll try that!