本文共 560 字,大约阅读时间需要 1 分钟。
using UnityEngine;using System.Collections;using UnityEngine.Events;//引用事件命名空间,这个必须要有using UnityEngine.UI;//引用UI命名空间public class Test : MonoBehaviour { // Use this for initialization void Start () { //定义Action,并赋予delegate方法 UnityAction<Button> btnActions = new UnityAction<Button>(onClick); //找到Button控件,并订阅事件 Button btn = gameObject.GetComponent<Button>(); btn.onClick.AddListener(btnActions); } void onClick(Object obj) { Debug.Log("button==========="); Debug.Log("button-----------" + obj.name); }} |
转载于:https://www.cnblogs.com/ZeroMurder/p/5842761.html