在面板上添加一个按钮
创建代码TestPanel如下:
- using UnityEngine;
- using System.Collections;
- public class TestPanel : MonoBehaviour
- {
- public GameObject button;
- // Use this for initialization
- void Start()
- {
- button = transform.FindChild("Button").gameObject;
- //给按钮添加NGUI委托事件
- UIEventListener.Get(button).onClick += TestButton;
- }
- // Update is called once per frame
- void Update()
- {
- }
- void TestButton(GameObject go)
- {
- Debug.Log("你点击了"+go.name);
- }
- }
将代码拖到panel上