unity assign button onclick

C#
public Button yourButton;	

void Start () 
{
	Button btn = yourButton.GetComponent<Button>(); //Grabs the button component
	btn.onClick.AddListener(TaskOnClick); //Adds a listner on the button
}	
void TaskOnClick()
{
	Debug.Log ("You have clicked the button!");
}
Source

Also in C#: