Sunday, May 31, 2015

EventHandling for Unity 4.6 UI Event system

Hello All:

Unity 4.6 comes with new UI system which has different way of handling different event like mouse over, mouse out, mouse in, click etc.
In this post I will share how to handle these events properly in Unity 4.6 UI. Unity 4.6 UI provides following Interfaces to handle these events
  • IPointerEnterHandler
  • IPointerClickHandler
  • IPointerExitHandler
Full List can be found here.

Following code shows how to handle these interfaces
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.EventSystems;

public class AwesomeGameObject : IPointerEnterHandler, IPointerClickHandler, IPointerExitHandler
    void Awake()


    public void Start()

    public void OnPointerEnter(PointerEventData eventData)
        //handle this for pointer enter

    public void OnPointerClick(PointerEventData eventData)
        //Handle this for click

    public void OnPointerExit(PointerEventData eventData)
        //Handle this for exit

Hope this helps. Happy coding.
Thanks for printing this post. Hope you liked it.
Keep visiting and sharing.


Post a Comment