京城游戏人-Day13: 获取被点击的 Button 以及其上的文字内容
-
-
获取被点击的 button:
var button = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject获取 button 上的文字内容:
Debug.Log(button.GetComponentInChildren<Text>().text);
-
-
本文介绍了如何在Unity中通过代码获取被点击的Button及其上面的文字内容,利用EventSystem.current.currentSelectedGameObject获取Button,再使用GetComponentInChildren<Text>()获取Button上的文字。
-
-
获取被点击的 button:
var button = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject
获取 button 上的文字内容:
Debug.Log(button.GetComponentInChildren<Text>().text);
-
-
7787
5521

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