2D Toolkit Forum

2D Toolkit => Support => Topic started by: xecut on May 10, 2013, 04:12:47 am

Title: tk2dButtons not working
Post by: xecut 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
Title: Re: tk2dButtons not working
Post by: unikronsoftware 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.
Title: Re: tk2dButtons not working
Post by: xecut 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!
Title: Re: tk2dButtons not working
Post by: mradebe_eti 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  :)
Title: Re: tk2dButtons not working
Post by: unikronsoftware on July 15, 2013, 11:00:31 pm
What do you mean by "trigger my new scene"?
Title: Re: tk2dButtons not working
Post by: mradebe_eti 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.
Title: Re: tk2dButtons not working
Post by: unikronsoftware 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.
Title: Re: tk2dButtons not working
Post by: mradebe_eti 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?
Title: Re: tk2dButtons not working
Post by: unikronsoftware 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?
Title: Re: tk2dButtons not working
Post by: fsadeq on July 16, 2013, 12:52:58 pm
Is there a way to pass parameters through the function calls?
Title: Re: tk2dButtons not working
Post by: unikronsoftware 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.
Title: Re: tk2dButtons not working
Post by: fsadeq 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.
Title: Re: tk2dButtons not working
Post by: unikronsoftware 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.
Title: Re: tk2dButtons not working
Post by: mradebe_eti on July 16, 2013, 06:56:23 pm
I finallly got it to work. I forgot to set my build settings before.  :P

Thanks!!
Title: Re: tk2dButtons not working
Post by: fsadeq 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 )
Title: Re: tk2dButtons not working
Post by: unikronsoftware on October 23, 2013, 12:24:50 pm
1. When you press play, is the sprite changing / removing the boxcollider? is it present when playing.
2. Is the box collider at the same location? Is it by chance clipping into the camera?
Title: Re: tk2dButtons not working
Post by: fsadeq on October 23, 2013, 01:38:52 pm
I moved some things around before I read your reply and it is working now. Perhaps something was clipping? I'm not sure, but I'll keep this in mind if I encounter the issue again. Thanks.