Hi there,
My question is a short one. I’ve been looking for a reference on a Canvas selectable button. The button itself does not call a function when clicked, it should just wait to see if it has been highlighted.
I have a script that was put directly on the button itself but I do not know how to write an “if statement” on “if this button is selected then…” in C#.
Add script containing this code to your Button:
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class YourScript : MonoBehaviour, IPointerEnterHandler, ISelectHandler
{
public void OnPointerEnter(PointerEventData eventData)
{
//do your stuff when highlighted
}
public void OnSelect(BaseEventData eventData)
{
//do your stuff when selected
}
}
cant find any new info on this topic.
OnPointerEnter() only works with the mouse.
How can I check if a button is highlighted while using keyboard navigation?
thank you