Hello Guest

Author Topic: Dynamic text buttons  (Read 5603 times)

k3ch0ng

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Dynamic text buttons
« 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 ?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Dynamic text buttons
« Reply #1 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.


k3ch0ng

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Dynamic text buttons
« Reply #2 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);
    }