void Start()
{
ClosureTest();
}
public Button[] btn;
private void ClosureTest()
{
for (int i = 0; i < 5; i++)
{
int num = i; //如果不在使用btn回调前声明变量并把i的值赋过去,i就会永远变成5..
btn[i].onClick.AddListener(() =>
{
Debug.Log(num);
});
}
}