- Home /
Can i use 2 buttons or many more with one function?
Hi, there i am trying to create a function onClick with 2 or more buttons who call from it, a flaot or int.How can i do that.I succeeded with 2 functions and 2 buttons but i need in public void ClickLevel () to have many buttons attached with a number for int.Because with int i make custom object and i need every button to have different number.
Answer by RobAnthem · Feb 12, 2019 at 04:30 PM
You would just add a parameter to your function and then feed the parameter through the buttons.
So your ClickLevel() would be
public void ClickLevel(int level)
{
Debug.Log("Clicked level: " + level.ToString());
}
In the inspector when you assign the button functions, you can assign the int of the level.
Answer by RobAnthem · Feb 12, 2019 at 04:30 PM
You would just add a parameter to your function and then feed the parameter through the buttons.
So your ClickLevel() would be
public void ClickLevel(int level)
{
Debug.Log("Clicked level: " + level.ToString());
}
In the inspector when you assign the button functions, you can assign the int of the level.
Thank you.It worked, i tryint the same 1 day ago but i dident have same result.Thank you again.
No problem. I'll move this comment to answers, in case anyone in the future has the same question.