public class myButtonEvent : MonoBehaviour { delegate void Proxy(); // Use this for initialization void Start () { Debug.Log ("myButtonEvent---start"); Proxy pxy = OnMyClick; //可以直接赋值,其实就是函数指针 pxy += OnMyClick; //可以这样加 pxy += new Proxy (OnMyClick);//也可以这样加 pxy (); //调用 Button blt = GetComponent<Button> (); //blt.onClick += pxy; //onclick并不是一个委托,是一个普通类 blt.onClick.AddListener (OnMyClick); } // Update is called once per frame void Update () { } public void bltClick(){ Debug.Log ("bltclick"); } public void OnMyClick(){ Debug.Log ("OnMyClick()"); } }
原文:http://www.cnblogs.com/timeObjserver/p/5965537.html