when i Instantiate some gameobject with button component ,i want to those button run function(with value) when i click,But even though every function show an impossible number ------temp+1
void Start()
{
int temp = Random.Range(5, 10);
for (int i = 0; i < temp; i++)
{
GameObject temp2 = Instantiate(card);
temp2.transform.Find("Canvas/button").GetComponent<Button>().onClick.AddListener( ()=> chosecard(i));
temp2.transform.Find("Canvas/text").GetComponent<Text>().text = (i+1).ToString();
temp2.transform.position = new Vector2(startpos.position.x + 13f/(temp-1)*i, -4f);
cards.Add(temp2);
}
}
line 8 ,every chosecard showed temp+1
– LikeDrogenN