Hello Guest

Author Topic: tk2dButtons not working  (Read 11609 times)

xecut

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
tk2dButtons not working
« on: May 10, 2013, 04:12:47 am »
I've set up a tk2dButton sprite, also I have setup the button down/up sprites.

But when I click on the sprite, there is no effect. the scale of the sprite is 675f, 675f, 675f. Pretty big.

Will that affect the sprite? if not, what did I do wrong?

I followed the steps from this tutorial http://www.youtube.com/watch?v=Sp2VOlaOBMk

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButtons not working
« Reply #1 on: May 10, 2013, 10:59:21 am »
Do you have a collider on the sprite? Is the collider thickness intersecting the camera? Try a z scale of 0.1 to see if that changes anything.

xecut

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: tk2dButtons not working
« Reply #2 on: May 11, 2013, 05:33:45 am »
Thank you for your help, after putting colliders on the sprite, changed collider depth to 0.2 (shouldn't matter), and scaled z to 0.1, it worked!

mradebe_eti

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: tk2dButtons not working
« Reply #3 on: July 15, 2013, 08:58:34 pm »
Hi,

I'm new to Unity and 2D toolkit, so I think this is a simple question. I'm trying to get a pressed button to trigger my new scene. What do I need to do?

Thanks  :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButtons not working
« Reply #4 on: July 15, 2013, 11:00:31 pm »
What do you mean by "trigger my new scene"?

mradebe_eti

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: tk2dButtons not working
« Reply #5 on: July 15, 2013, 11:11:51 pm »
I want to have a button on my current scene open up a new scene when pressed.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButtons not working
« Reply #6 on: July 15, 2013, 11:31:10 pm »
1. Create a function in a behaviour somewhere. Attach it to a gameobject A.
void LoadMyNewLeveL() {
  Application.LoadLevel("levelname");
}

2. Create a UI manager, and drag the button prefab into the scene. http://unikronsoftware.com/2dtoolkit/doc/2.00/ui/getting_started.html
Click on the button, and drag gameObjet A into the "Send Message" target slot on the button.

3. Type LoadMyNewLevel into the OnClick event box.

That should be it.

mradebe_eti

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: tk2dButtons not working
« Reply #7 on: July 16, 2013, 12:42:50 am »
Here is the function I created. I named it TestScene.cs (the same name as my current scene).

using UnityEngine;
using System.Collections;

public class TestScene : MonoBehaviour {
   
   void LoadMyNewLevel() {
      Application.LoadLevel("TestScene02");
      }
}

1. I attached this to GameObject A.

2. I created a UI Manager and dragged the button prefab onto my scene.

3. I clicked on the button and dragged GameObject A into the "Send Message" target slot on the button.

4. I typed LoadMyNewLevel into the On Clicked Method Name event box.

I tested it and it still does not work. Am I missing something?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButtons not working
« Reply #8 on: July 16, 2013, 10:30:56 am »
Do you get any error in the console window when clicking on the button / starting the game? If you put a Debug.Log in LoadMyNewLevel, is it being called?

fsadeq

  • 2D Toolkit
  • Sr. Member
  • *
  • Posts: 353
    • View Profile
Re: tk2dButtons not working
« Reply #9 on: July 16, 2013, 12:52:58 pm »
Is there a way to pass parameters through the function calls?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButtons not working
« Reply #10 on: July 16, 2013, 12:58:23 pm »
What kind of parameters? As of 2.1, the message sending will send a reference to self (i.e. tk2dUIItem sender) to the recepient of the button. You can't send arbitrary parameters though.

fsadeq

  • 2D Toolkit
  • Sr. Member
  • *
  • Posts: 353
    • View Profile
Re: tk2dButtons not working
« Reply #11 on: July 16, 2013, 02:39:10 pm »
Yea, arbitrary parameters. Like if you just had some simple buttons that you wanted to pass an index through, e.g. LoadItem(int index);

I guess in this case you'd have to just code it differently and listen for the button events instead.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dButtons not working
« Reply #12 on: July 16, 2013, 03:39:17 pm »
Yup. You could do all sorts of game speicifc things, eg. use the button's "tag" field / name to determine what to do.

mradebe_eti

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: tk2dButtons not working
« Reply #13 on: July 16, 2013, 06:56:23 pm »
I finallly got it to work. I forgot to set my build settings before.  :P

Thanks!!

fsadeq

  • 2D Toolkit
  • Sr. Member
  • *
  • Posts: 353
    • View Profile
Re: tk2dButtons not working
« Reply #14 on: October 22, 2013, 09:15:36 pm »
I'm running 2.2.3, and have a question regarding the most basic of buttons. This is the first time I've really started using them and for some reason I can't get buttons to work if the tk2dUIItem script is attached to the main sprite. If I create an empty game object with just the tk2dUIItem and box collider, then add the sprites as children, it works. Any idea why? Really scratching my head here. So, basically:

Scenario 1 (doesn't work):

-GameObject (has the sprite button graphic, tk2dUIItem, Box Collider )
     -GameObject( has the text )

Scenario 2 (works):

-Gameobject (has tk2dUIItem, Box Collider )
     -GameObject (has the sprite button graphic)
     -GameObject( has the text )