zoukankan      html  css  js  c++  java
  • Unity3D NGUI 给button按钮添加单间事件

    Unity3D中, NGUI 给button按钮添加单间事件的方法很多,在这里只给推荐一种比较常用的方法。

    推荐方法:使用UIListener。

    1、给button组价添加上UIListener。选择Button-Component-NGUI-Internal-Event Listener,点击“Event Listener”即可添加到button上。注意,挂在按钮上就可以,它没有任何参数。

    如图:

    2、调用方法:在任何一个脚本或者类中即可得到按钮的点击事件、把如下代码放在任意类中或者脚本中。

    using UnityEngine;
    using System.Collections;
    
    public class BtnNUGUI : MonoBehaviour {
    
    
      void Awake()
      {
        GameObject button = GameObject.Find("UI Root (2D)/Camera/Anchor/Panel/Button");
        UIEventListener.Get(button).onClick = ButtonClick;
      }
    
      void ButtonClick(GameObject button)
      {
        Debug.Log("NGUI button name :"+button.name);
      }
    
    // Use this for initialization void Start () { } // Update is called once per frame void Update () { } }

      

    Ethical behaviour is ... 合乎道德的行为是...... Doing the right thing,even when no one is watching. 在任何时候,即使没有人看见也要做正确的事情。
  • 相关阅读:
    页面的三大家族
    封装函数
    图片自动播放的案例
    动画封装
    长图滚动案例+点名册案例
    时钟案例
    伪随机数,随机数种子seed
    numpy.tolist( )函数
    countif( ) 函数判断当前单元格的身份证号码是否重复出现
    Excel技巧
  • 原文地址:https://www.cnblogs.com/growthTree/p/4693661.html
Copyright © 2011-2022 走看看