码迷,mamicode.com
首页 > 其他好文 > 详细

ugui使用代码动态添加Button.OnClick()事件

时间:2015-03-18 06:42:00      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:ugui使用代码动态添加button.onclick()事件

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.Events;
using System.Collections.Generic;

public class PersonalInformation : MonoBehaviour
{

    void Start()
    {
        List<string> BtnsName = new List<string>();
        BtnsName.Add("Text11(Clone)");
        foreach (string btnsName in BtnsName)
        {
            GameObject btnObj = GameObject.Find(btnsName);
            Button btn = btnObj.GetComponent<Button>();
            btn.onClick.AddListener(delegate()
            {
                this.OnEmailInformation(btnObj);
            });
        }
    }


 public void OnEmailInformation(GameObject sender)
    {
        if (sender.name == "Text11(Clone)")
        {          
            Debug.Log("添加成功");
        }

    }

}


//记住这里Text11(Colone)是实例化出来的物体名字,记住实例化出来的物体名字后面都需要加上(Colone)

本文出自 “酷酷小乔” 博客,请务必保留此出处http://5152481.blog.51cto.com/5142481/1621583

ugui使用代码动态添加Button.OnClick()事件

标签:ugui使用代码动态添加button.onclick()事件

原文地址:http://5152481.blog.51cto.com/5142481/1621583

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!