private Button Btn; 要添加事件的UI
在Start方法中,查找这个游戏对象所在的位置赋值
Btn = GameObject.Find("button").transform.Find("Button ").GetComponent<Button>();
void Reduction(Transform item)
{
}
void Reduction()
{
}
动态添加事件(有参)
Btn.onClick.AddListener(delegate{ Reduction(item);});
动态添加事件(无参)
Btn.onClick.AddListener(Reduction());
删除所有动态添加事件
Btn.onClick.RemoveAllListeners();
删除动态添加事件(有参函数的删除)
Btn.onClick.RemoveListener(delegate{ Reduction(item);});
删除动态添加事件(无参函数的删除)
Btn.onClick.RemoveListener(Reduction());