How to get reference on which UI button is clicked.

I have a UI Based game.

I have created list of UI Buttons in project.

gameController is an empty Gameobject with gameController script. Which has reference for all the UI Buttons as List.

For each UI Button I have added On Click event and referred gameController public function.

I want to get which button is clicked like
//javascript example

function clickEventFunction(event){
 event.currentTarget;
}

You have 2 major ways of doing something like that:

1)The one I’d not recommend:

-Add this function to your “controller script”:

public void IWantTheName(string name) //this MUST be public and also have to return void, and only accept int, float, bool, string, and Object parameters
{
   //do something here
}

-Then on every button in Inspector view in OnClick() section you add:
->Editor and runtime
->As object select your object that contains “controller script”
->As function select “Controller script”=>IWantTheName
->And provide some unique string value in that textbox

That’s all.

2)The way I recommend to do:

-Add this function to your “controller script”:

internal void IWantTheName(string name) //this no longer needs to be public in order to work and don't have the restrictions of first example
{
   //do something here
}

you can as well now have multiple variables passed like this:

internal void IWantTheName(string name, Button buttRef, int someVal) //this no longer needs to be public in order to work and don't have the restrictions of first example
{
   //do something here
}

-Then add this script either to your buttons prefab or to each button, in the end just every button supported by your “controller script” should contain this script:

public class ButtonResponder : MonoBehaviour
{
    [SerializeField]
    private ControllerScript controllerRef;//you can set this in Inspector or you can find this script in "Awake" function if this script is not contained in any GameObject (e.g. if it is not added to GameObject), you won't need this if your script is static
    private Button buttRef;
    private void Awake()
    {
        buttRef = GetComponent<Button>();//gets ref to this script's button.
    }
    private void Start()
    {
        if (buttRef != null && controllerRef != null) buttRef.onClick.AddListener(() => { controllerRef.IWantTheName(enter your values required by controller over here); });
    }
}

That’s it. Also with script way you can use different events than onClick like Down, Up, etc.