2D Toolkit Forum
2D Toolkit => Support => Topic started 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
-
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.
-
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!
-
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 :)
-
What do you mean by "trigger my new scene"?
-
I want to have a button on my current scene open up a new scene when pressed.
-
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.
-
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?
-
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?
-
Is there a way to pass parameters through the function calls?
-
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.
-
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.
-
Yup. You could do all sorts of game speicifc things, eg. use the button's "tag" field / name to determine what to do.
-
I finallly got it to work. I forgot to set my build settings before. :P
Thanks!!
-
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 )
-
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?
-
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.