实际操作中 给Button 添加点击事件 是不能带参数的,那么怎样在 点击事件方法体中 拿到当前点击 Button 组件,
方法如下(注:写在点击方法体中)
var buttonSelf = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject
这样就可以获取Button自身的属性和子物体(如Text)
Text text=buttonSelf.Find("Text").GetComponent<Text>();
本文介绍如何在Unity中为Button绑定点击事件时获取被点击Button自身及其子物体的组件,通过EventSystem.current.currentSelectedGameObject可以轻松实现。

2093

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



