I tried creating a public variable and then referencing the EventSystem object from the Inspector of the gameObject the script is attached to, but whenever I try to access a variable from EventSystems,
I get a NullReference Exception: Object reference not set to an instance of an object.
I tried finding it with GameObject.Find()
but apparently I can't cast the gameObject
to EventSystem.EventSystem
with in-built cast.
I'm not sure what to do. I just want to access
EventSystem.currentSelectedGameObject.name
to find out which UI object in Canvas was selected.
Here is what you want, see documentation here.