2D Toolkit Forum

2D Toolkit => Support => Topic started by: k3ch0ng on June 28, 2012, 03:53:58 pm

Title: Dynamic text buttons
Post by: k3ch0ng on June 28, 2012, 03:53:58 pm
Hi,

Im trying to create buttons with dynamic text e.g. multiply level buttons each assign a grade once the level is complete.

Whats the best approach to do this ?

Also is there a way to find out which button is pressed within the messagename function, or do I have to assign each button a new funtion name ?
Title: Re: Dynamic text buttons
Post by: unikronsoftware on June 28, 2012, 05:16:48 pm
If you hook the buttons up using the event mechanism
http://unikronsoftware.com/2dtoolkit/doc/html/classtk2d_button.html#a58db4d481f8169b557d8d8d6bcede732

instead of just using the targetObject | messageName, you get a link to the tk2dButton which invoked the callback. You can then use tk2dButton.gameObject to get the gameObject that invoked it, and so on.

Title: Re: Dynamic text buttons
Post by: k3ch0ng on June 30, 2012, 01:11:03 am
Cool thanks. If anyones intrested the code is something like this:

Just drag all the buttons u need into the buttons array.


   public tk2dButton[] buttons;

   void Awake () {
      for(int n = 0; n < buttons.Length; n++)
         buttons[n].ButtonUpEvent += ButUp;
   }
   
    void ButUp(tk2dButton b)
    {
      Debug.Log("ButUp " + b.gameObject.name);
    }