I am creating buttons for each level through script as shown below
private void CreateLevelButtons()
{
for (int i = 1; i <= no_of_levels; i++)
{
Button button = Instantiate(button_prefab);
button.GetComponentInChildren<Text>().fontSize = 12;
button.GetComponentInChildren<Text>().text = "Level " + i.ToString();
button.transform.SetParent(content.transform, false);
button.onClick.AddListener(() => OnClickLevelButton());
}
}
In OnClickLevelButton() function I want to determine the level number of the button that was clicked. Is there a way to associate a number to a button so that i can access that number later when the user clicks on the button?
OnClickLevelButton(i)
method? \$\endgroup\$ – sjoerd216 Apr 26 '18 at 9:52