You can definitely do this. I don't know whats wrong with your script - I dont know how you have attached that in the scene, and I'm not sure why you're constantly binding and unbinding the events - you can do this a lot easier with one script and just filter the events from the script itself. Here's a working example. Make sure you have a tk2dUIManager with multitouch enabled for multitouch to work properly.
using UnityEngine;
using System.Collections;
public class ButtonTest : MonoBehaviour {
public tk2dUIItem btnLeft, btnRight, btnJump;
bool left = false, right = false, jump = false;
void OnEnable() {
btnLeft.OnDownUIItem += ButtonDown; btnRight.OnDownUIItem += ButtonDown; btnJump.OnDownUIItem += ButtonDown;
btnLeft.OnReleaseUIItem += ButtonRelease; btnRight.OnReleaseUIItem += ButtonRelease; btnJump.OnReleaseUIItem += ButtonRelease;
}
void OnDisable() {
btnLeft.OnDownUIItem -= ButtonDown; btnRight.OnDownUIItem -= ButtonDown; btnJump.OnDownUIItem -= ButtonDown;
btnLeft.OnReleaseUIItem -= ButtonRelease; btnRight.OnReleaseUIItem -= ButtonRelease; btnJump.OnReleaseUIItem -= ButtonRelease;
}
void ButtonDown(tk2dUIItem item) {
HandleButton(item.name, true);
}
void ButtonRelease(tk2dUIItem item) {
HandleButton(item.name, false);
}
void HandleButton(string name, bool val) {
switch (name) {
case "left": left = val; break;
case "right": right = val; break;
case "jump": jump = val; break;
}
}
void OnGUI() {
GUILayout.Label(string.Format("LEFT: {0} RIGHT: {1} JUMP: {2}", left, right, jump));
}
}