- Home /
How to attach hover event to Button?
HI,
I have a UI Button. Can I attach a hover event listener to it like "onClick.AddListener()"? Or how to create a hover event for a button in new UI?
Answer by Tomer-Barkan · Sep 30, 2015 at 06:02 PM
You need to write your own script that implements the events IPointerEnterHandler and IPointerExitHandler, then attach it to the button object.
Thanks a lot! I understood that I need to create two scripts that implement IPointer interfaces and attach them to the button. If so - that is awesome!
You can have one script that implements both interfaces, no need for two separate scripts. Let us know how it goes so we can close the question if it works.
Answer by Delivionos · Jul 22, 2019 at 10:29 AM
Very simple you can attach an Event Trigger ( Script ) to your GameObject.
Hovering in out of that object will trigger your specified function.
Answer by Ana-Mery · Oct 12, 2018 at 12:48 PM
Add an EventTrigger (Pointer Enter type).
This worked for me, thank you!
Answer by snowinrain · Jan 19, 2021 at 02:18 AM
Change Transition of Button component to "Sprite Swap"
Answer by PankajOnUnity · Apr 25, 2018 at 06:11 PM
OnHover custom event UnityEvent type https://youtu.be/wAQEbmcv_LQ