2D Toolkit Forum
2D Toolkit => Support => Topic started 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?
-
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){ }"
-
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?
-
You have to link up to it from code like so:
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.