How to Unity

Using Pointer-Related Events in Unity UI

How to use pointer-related interfaces and events in Unity

Daniele Quero, PhD
Nerd For Tech
Published in
4 min readJun 11, 2024

--

Unity allows the implementation of up to 5 interfaces to handle pointer-related events while working with UI.

Namely, the interfaces are:

which you can explore better in the Official Scripting API manual. Each interface exposes a method, respectively:

OnPointerClick(PointerEventData pointerEventData)
OnPointerDown(PointerEventData pointerEventData)
OnPointerEnter(PointerEventData pointerEventData)
OnPointerExit(PointerEventData pointerEventData)
OnPointerUp(PointerEventData pointerEventData)

Similar to the collider ones, those methods are triggered when the user interacts with a UI element using the mouse pointer. Of course, the element should have a script attached, implementing the interface. An example of implementation would be:

OnPointerenter(PointerEventData pointerEventData){
//stuff to do when the pointer hovers above THIS UI element
}

--

--

Daniele Quero, PhD
Nerd For Tech

A professional developer with passion for game developing and skill-growing. A former Nuclear Physics Researcher who changed his life to pursue his dreams