Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 如何从脚本引用UI事件系统?_Unity3d_Unityscript - Fatal编程技术网

Unity3d 如何从脚本引用UI事件系统?

Unity3d 如何从脚本引用UI事件系统?,unity3d,unityscript,Unity3d,Unityscript,我尝试创建一个公共变量,然后从脚本所附加的游戏对象的检查器中引用EventSystem对象,但每当我尝试从EventSystems访问变量时 我得到一个NullReference异常:对象引用未设置为对象的实例 我试着用GameObject.Find()找到它,但显然我无法用内置模式将GameObject转换为EventSystem.EventSystem 我不知道该怎么办。我只想访问 EventSystem.currentSelectedGameObject.name 要找出画布中的哪个UI对

我尝试创建一个公共变量,然后从脚本所附加的游戏对象的检查器中引用EventSystem对象,但每当我尝试从EventSystems访问变量时

我得到一个NullReference异常:对象引用未设置为对象的实例

我试着用
GameObject.Find()
找到它,但显然我无法用内置模式将
GameObject
转换为
EventSystem.EventSystem

我不知道该怎么办。我只想访问

EventSystem.currentSelectedGameObject.name


要找出画布中的哪个UI对象被选中。

这里是您想要的,请参阅文档


我认为我使用了
EventSystem.current.currentSelectedGameObject.name
获得了它,但我仍然得到了相同的NullReference异常…显然
EventSystem.current.currentSelectedGameObject
对所有内容都返回Null。我想这就是问题所在。我不明白为什么它认为我没有选择任何东西,而我显然能够使画布中的Scroll Rect对象正常工作。求助于
Camera.main.ScreenPointToRay(Input.mousePosition)
Physical.Raycast()
来查找游戏对象,因为事实证明事件系统比预期的复杂。
EventSystem.current