I'm trying to have a list of check boxes with a vertical scrolling (Based on Example 7 -Scroll view panel).
I'm using a prefab of a check box. Everything is working fine when I add prefabs as children of the Grid via the editor.
I'm missing out something when it comes to dynamically instantiate: all the check boxes are positioned on the same position.
Below is the script attached to the draggable panel.
public class checkboxList: MonoBehaviour
{
public GameObject checkbox;
UIGrid grid;
void Awake()
{
grid = ((UIGrid)((transform.Find("UIGrid")).GetComponent("UIGrid")) );
}
void Start ()
{
List<Game.contact> MyContactList = Game.ContactList.get();
for(int i = 0; i < MyContactList.Count; i++)
{
GameObject item = NGUITools.AddChild( transform.Find("UIGrid").gameObject,checkbox);
((UILabel)item.transform.Find("Label").GetComponent("UILabel")).text = MyContactList[i].fullname;
item.transform.name = "item" + i.ToString();
}
GameObject.Find("UIPanel (Clipped View)") .GetComponent<UIDraggablePanel>().ResetPosition();
}
void Update ()
{
grid.Reposition();
}
}
Please help.