UGUI 查找按钮名称

来源:互联网 发布:caffe中softmax 编辑:程序博客网 时间:2024/06/07 13:12
昨天在做项目的时候,按钮是符合条件才会出现的,所以我需要在点击按钮时获得这个按钮究竟是哪一个,在询问了N多人之后,还是百度告诉了我这个答案。
string name = EventSystem.current.currentSelectedGameObject.GetComponent<Button>().name;

string name = EventSystem.current.currentSelectedGameObject.GetComponent<xxx>(),这个方法通过你的点击,返回了点击物体,因为我需要的是名字,所以用的这种写法,主要看你需要什么了。对了,记得引入using UnityEngine.EventSystems;