【发布时间】:2015-06-20 11:11:59
【问题描述】:
我尝试创建一个公共变量,然后从脚本附加到的游戏对象的检查器中引用 EventSystem 对象,但是每当我尝试从 EventSystems 访问变量时,
我收到 NullReference 异常:对象引用未设置为对象的实例。
我尝试使用GameObject.Find() 找到它,但显然我无法使用内置转换将gameObject 转换为EventSystem.EventSystem。
我不知道该怎么办。我只想访问
EventSystem.currentSelectedGameObject.name
找出在 Canvas 中选择了哪个 UI 对象。
【问题讨论】:
-
我以为我使用
EventSystem.current.currentSelectedGameObject.name得到了它,但我仍然得到相同的 NullReference 异常... -
显然
EventSystem.current.currentSelectedGameObject为所有内容返回 Null。我想这就是问题所在。我不明白为什么当我清楚地能够使画布中的 Scroll Rect 对象正常运行时,它认为我什么都没有选择。 -
求助于
Camera.main.ScreenPointToRay(Input.mousePosition)和Physics.Raycast()寻找游戏对象,因为事实证明EventSystem 比预期的要复杂。
标签: unity3d unityscript