I’m using multiple TextMeshPro buttons and can assign an OnClick() handler method to each button individually. Is it also possible to have one OnClick() method for multiple buttons that can then somehow distinguish which button was pressed. This would e.g. be possible if there was the button reference parameter in the OnClick() from which the click came, but I could not find any information that this is possible.
You can just give a parameter to your OnClick() method declaration and a field for assigning something to that parameter shows up on your OnClick() assignment for the button.
Ah, nice, thank you!
I had not noticed before that a parameter shows up in the inspector when I assign a method with a parameter to the Button OnClick() field.
Also, I have found this piece of code that helps when creating buttons programmatically:
for(int i = 0; i < 10; i++) {
…
button.onClick.AddListener(delegate () { ButtonPressed(i); });
}