I am having trouble with UIItem and am wondering where the problem originates. I have a screen with multiple objects that are the same. They are buttons that allow users to select a level to play. I found that some of these buttons doesn't respond to being clicked or when clicked fires multiple times. Below is the script attached to the game object.
The other components I have attached are tk2dSprite, tk2dButton, tk2dUIItem, and Pool Object (prefactory - >
http://www.booncotter.com/unity-prefactory-a-better-pool-manager/). I am using the tk2dUIManager and tk2dCamera as well.
Is there any reason why this is happening?
using UnityEngine;
using System.Collections;
public class PageItem : MonoBehaviour {
public GameObject system;
public tk2dUIItem button;
int level, index;
void Awake()
{
string[] nameArray = name.Split(' ');
level = int.Parse(nameArray[1]);
index = int.Parse(nameArray[3]);
system = transform.root.gameObject;
renderer.enabled = true;
}
void Start()
{
setTransform();
}
private void setTransform()
{
float posX = 1f / ((float)PageInfo.itemsPerRow + 1), posY = 1f/ ((float)PageInfo.itemsPerColumn + 1);
int row = Mathf.CeilToInt((index + 1)/ (float)PageInfo.itemsPerRow);
int column = index + 1 - ((row - 1) * PageInfo.itemsPerRow);
transform.localPosition = new Vector3((column * posX) - 0.5f, 0.5f - (row * posY), -1f);
transform.localScale = Vector3.one;
}
// 2Dtoolkit
void OnEnable()
{
button.OnClick += pickTeam;
}
private void pickTeam()
{
system.SendMessage("pickTeam", level);
}
}