I want to send multiple parameter on button click from inspector?
Unity isn't allowing that to do, how can I achieve that? is there any other way? There are dozens of buttons and I am using same method for all buttons but sending different parameters, now I need to send multiple types of parameters. Can't figure out how?
Calling Unity function from the Editor has limitation. It can only take one parameter and the function must be a non static
function.
This is why it is important to know how to subscribe to events from code. Below is an example of a function that gets called when a Button
is clicked. It passes in a string and an integer to that function. Simple, drag the Button
to the some Button slot in the Editor and this should work.
public Button someButton;
void OnEnable()
{
//Register Button Events
someButton.onClick.AddListener(() => buttonCallBack("Hello Affan", 88));
}
private void buttonCallBack(string myStringValue, int myIntValue)
{
Debug.Log("Button Clicked. Received string: " + myStringValue + " with int: " + myIntValue);
}
void OnDisable()
{
//Un-Register Button Events
someButton.onClick.RemoveAllListeners();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With