Member-only story
How to Unity
Using Pointer-Related Events in Unity UI
How to use pointer-related interfaces and events in Unity
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
}