How to get the GameObject in a callback function

I add a callback function with no parameter to the “On Click()” list of a Button. Now I want to get the reference of the Button object in the callback function (Because the Button will be added many times dynamically at runtime and I want to know which one I am clicking). So, how should I do?

I’ve been bothered by this problem for a week, and can’t find any solution in the Unity Manual or Google (Maybe because my English is poor…). Please help me, thank you very much~

Try attaching this script to the button.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ClickEventHandler : MonoBehaviour, IPointerClickHandler
{
	public void OnPointerClick(EventSystems.PointerEventData eventData)
	{
		YourFunction(gameObject);
	}
}

IPointerClickHandler allows you to receive click event and do what you want.

Actually, the new Event System is flexible, so learn how it works, how it sends events. You will love it.