Detecting which UI button was pressed within canvas?


I have like 10 buttons on my UI and I gotta check which one was touched. I was using the following logic and it was working fine, but now I am getting this error for some reason:

NullReferenceException: Object reference not set to an instance of an object
DetectButton.Start () (at Assets/Scripts/DetectButton.cs:14)

Any ideas what could be going on? Here is my code (attached to the canvas), and I am using Unity version 5.1.0f3. If you need any other info I will gladly provide, thanks in advance

void Start()
	this.GetComponent<Button>().onClick.AddListener(() => 

		if ( == "btnJogadores2")
			print ("2 jogadores");
			jogadores = 2;

you can pass the gameobject as a parameter of the function via inspector that you call while the button is clicked .

This is the best mehod that I use to dedect which button is clicked