如何用代码控制NGUI的点击事件

using UnityEngine;
using System.Collections;

public class TestNGUI : MonoBehaviour {
    public UILabel mylabel;
    public UIButton mybutton;
    // Use this for initialization
    void Start ()
    {
//        mylabel.text = "你好";
//        mylabel.fontSize = 50;  //int

        //必须给Button添加UIEventListener脚本
        //+=和=都可以
//        UIEventListener.Get (mybutton.gameObject).onClick = ClickButton2;
        UIEventListener.Get (mybutton.gameObject).onDoubleClick += ClickButton2;
    }
    
    // Update is called once per frame
    void Update () {
    
    }
//    public void ClickButton()
//    {
//        mylabel.text = "hello";
//    }

    public void ClickButton2(GameObject button)
    {
        mylabel.text = "hello";
    }
}

猜你喜欢

转载自blog.csdn.net/laoshaonian/article/details/50433453