Checking if button is highlighted with a controller (no mouse)

Hi guys,
I’m using a controller button to highlight 3 buttons (ammo selection).
The buttons get highlighted fine. The problem is that I need to execute a method when one of these buttons is highlighted. I don’t want the player to have to highlight the button THEN press OK. I found a whole bunch of threads on this but they all seem to involve a mouse. My game is played with a controller. The question is: How can I achieve this? I tried all the scripts found here and there but none of them work. Here is the last option I found. That code transforms the button into something else which I can’t access to make it intractable or not from another script. It also removes the OnClick that I would still like to keep for people not using a controller but using the keyboard instead. Any help would be appreciated. I spent all morning just trying to get this to work. I’m on 2018.3. Thanks.

using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

//Use the Selectable class as a base class to access the IsHighlighted method
public class BuckShotSelected : Selectable
{
    //Use this to check what Events are happening
    BaseEventData m_BaseEvent;

    void Update()
    {
        //Check if the GameObject is being highlighted
        if (IsHighlighted(m_BaseEvent) == true)
        {
            //Output that the GameObject was highlighted, or do something else
            Debug.Log("Selectable is Highlighted");
        }
    }
}

I had a similar problem where I needed to execute a task when a certain button was highlighted with the controller instead of the mouse. I’m not sure if this is the best way to do this but so far this is the only way I can figure out how to do it. Use EventSystem.current.currentSelectedGameObject to store the current highlighted button. Then just simply check the gameObjects name and run desired method.

public class ClassName: MonoBehaviour
{
    GameObject currentSelected;

    void Update()
    {
        currentSelected = EventSystem.current.currentSelectedGameObject;

        if(currentSelected.name == "NameOfButton")
        {
            ... run desired code or method
        }
    }
}

@Chrisv007 @Fuzysasquatch
The simplest way to implement this is with the ISelectHandler interface.
You can just add the interface to a MonoBehaviour on the button and there you have it:

public class UIButton : MonoBehaviour, ISelectHandler{
public void OnSelect(BaseEventData eventData)
{
//DO STUFF
}
}