标签: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