Recognising a particular instance

Hello to all

I am developing a game that uses mainly buttons.
At some point in my game, players have to choose teammates. What I did to achieve this is that I created a prefab of a game object (which contains a text and a button, the text is the name of the player and the button is the button that allows to select my teammate)
When the game starts, for each player who is not a team leader, an instance of my prefab will be created and specify for each person his name.

My problem is that I don’t see how to differentiate between my players when I click on the button to select them.

I’m going to clarify: since the instances are all clones, if I put a function when I click on my button ( like, Debug.Log("I select player " + IDplayer); ) how can the function make the difference between all the buttons and therefore the players.

If you have a solution I’m interested.

Thank you!

Instead of using the onClick event setup in the editor, just get a reference to each Button as you create it, and then attach your own listener with this function:

NOTE: if you are looping, beware of variable capture vs value capture!

Delegate / Action variable capture / value capture: