In Unity I have the following code:
public Button[] SearchPlayers;
void Start()
{
for(int i = 0; i < 10; i++)
{
// SearchPlayers[i].onClick.AddListener(Click(i));//here error
SearchPlayers[i].onClick.AddListener(Click);//not error
}
}
void Click(int i)
{
print(i+":button was clicked")
}
The problem is if you see my code there is an integer i
. So that value gives an error.How can I solve this error?