For someone that is still pretty newbish with not only Unity, but with C# as well, I found it very hard to understand the concept of incorporating a Basic Button and having it do something OTHER then play an audioclip. The documentation on this was very lacking. After finally "getting" it today, I think the biggest factor to the confusion was the example of listening to events in "Understanding UI System and Building your Own Components" (
http://www.unikronsoftware.com/2dtoolkit/docs/2.00/ui/system.html)
void OnEnable()
{
uiItem.OnDown += ButtonDown;
uiItem.OnClickUIItem += Clicked;
}
void ButtonDown()
{
Debug.Log("Button Down");
}
void Clicked(tk2dUIItem clickedUIItem)
{
Debug.Log("Clicked:" + clickedUIItem);
}
//Also remember if you are adding event listeners to events you need to also remove them:
void OnDisable()
{
uiItem.OnDown -= ButtonDown;
uiItem.OnClickUIItem -= Clicked;
}If you copy/paste the code as-is, you get the following error:
error CS0103: The name `uiItem' does not exist in the current context. The example is not clear that you need to have the class extend (if that's the right terminology) tk2dUIBaseItemControl, like:
public class MyCScript: tk2dUIBaseItemControl {
public GameObject lureObject;
void OnEnable()
{
uiItem.OnClick += specialMove;
}
void OnDisable()
{
uiItem.OnClick -= specialMove;
}
private void specialMove()
{
Debug.Log ("Yep");
}
}
This might seem simple and easy to debug, but for someone just starting out it was extremely frustrating. Everything else so far with 2D toolkit has been great so far though and I feel it's one of the best investments I've made so far.