How can i detect, which button was clicked ?

Hello,

I have three buttons in the scene. All of them are using same function when they are clicked. This function’s script is applied on Main Camera. But how can i know, that which button was clicked ?

Thanks.

Here we go.
I have found the solution,

Suppose you have two buttons say Btn1 ,Btn2 and you have written following code

if(GUI.Button(btnposition and size here,"Btn1"))//this is Btn1
{
func1(); //you call this function on button click
}

if(GUI.Button(btnposition and size here,"Btn2"))//this is Btn2
{
func1(); //you call same function on button click
}

Now to detect which button was clicked you can take two different boolean variables for these buttons click detection and use them as following

if(GUI.Button(btnposition and size here,"Btn1"))//this is Btn1
{
boolBtn1 = true;
boolBtn2 = false;

func1(); //you call this function on button click
}

if(GUI.Button(btnposition and size here,"Btn2"))//this is Btn2
{
boolBtn1= false;
boolBtn2=true;
func1(); //you call this function on button click
}

Hence true boolean will tell you here which btn was clicked. like if boolBtn1 true it will signify that Btn1 was clicked.

There could be other methods as well to achieve this but for the time you can use this.