2D Toolkit Forum

2D Toolkit => Support => Topic started by: inkoman on February 01, 2013, 12:30:56 am

Title: How do you "hold down" a tk2dButton?
Post by: inkoman on February 01, 2013, 12:30:56 am
Say I want to continuously call a function as long as I have a tk2dButton held down - how do I go about this?
Title: Re: How do you "hold down" a tk2dButton?
Post by: sfbaystudios on February 01, 2013, 12:35:05 am
If I'm not mistaken, just make sure there's a Collider on the object, and treat it like any other object.  While mouse down, cast a ray, and if the ray is hitting the object (which means clicking or finger on it), update a variable such as "beingTouched = true", and in the update(), " if (beingTouched){ }"
Title: Re: How do you "hold down" a tk2dButton?
Post by: inkoman on February 01, 2013, 12:52:17 am
Ah that may be an acceptable solution. I was looking through the documentation and found:

ButtonHandlerDelegate    
ButtonAutoFireEvent: Occurs every frame for as long as the button is held down.

Any idea where and how I would use this delegate?
Title: Re: How do you "hold down" a tk2dButton?
Post by: unikronsoftware on February 01, 2013, 04:39:05 pm
You have to link up to it from code like so:

Code: [Select]
void Start() {
   tk2dButton button = GetComponent<tk2dButton>(); // or use a drag&dropped variable
   button.ButtonAutoFireEvent += ButtonAutoFire;
}

void ButtonAutoFire(tk2dButton source) {
    Debug.Log("aaaaa!");
}

Its a standard c# event.