void Start ()
{
EventDelegate NormalAttackEvent = new EventDelegate(this, "OnHello"); //UIBUTTON的监听事件
GameObject.Find("Normal").GetComponent<UIButton>().onClick.Add(OnHello);
{
EventDelegate NormalAttackEvent = new EventDelegate(this, "OnHello"); //UIBUTTON的监听事件
GameObject.Find("Normal").GetComponent<UIButton>().onClick.Add(OnHello);
} //Start end
public void OnHello()
{
print("Hello world!");
}
本文介绍了一个简单的Unity脚本示例,展示了如何为UI按钮设置点击事件监听,并在按钮被点击时触发打印“Hello world!”的事件处理函数。通过创建事件委托并将其添加到按钮的onClick事件中实现。
1000

被折叠的 条评论
为什么被折叠?



