2D Toolkit Forum

2D Toolkit => Support => Topic started by: calebheale on July 16, 2014, 12:03:47 am

Title: Cant register event listeners
Post by: calebheale on July 16, 2014, 12:03:47 am
I have a tk2dUIUpDownButton script as a component on a game object that I would like to use as a button.
I have a second script to write my event handlers also as a component on the same game object
I am trying to access the uiItem to reference the events
In OnEnable for my custom script I am trying to access uiItem using the following:
tk2dUIItem ui = GetComponent<tk2dUIUpDownButton>().uiItem;

I get a null reference exception when trying to register my event handlers.

What am I doing wrong?
Title: Re: Cant register event listeners
Post by: unikronsoftware on July 16, 2014, 09:35:52 am
tk2dUIUpDownButton needs a UIItem to work. I suggest looking at the ui demo prefabs to see how they're wired up, or just base your design off one of the prefabs.
Title: Re: Cant register event listeners
Post by: calebheale on July 16, 2014, 02:56:46 pm
Thank you. That is exactly what I was missing. And yes, looking at the prefabs helped make a lot more sense of it.