2D Toolkit Forum

2D Toolkit => Support => Topic started by: soulareus on May 13, 2014, 11:27:15 pm

Title: How to add layout to tk2dUILayoutContainerSizer in code dynamically?
Post by: soulareus on May 13, 2014, 11:27:15 pm
      

I am trying to create a dynamic health bar using little dots to show health.  I want to use the LayoutContainerSizer.  I am getting an index out of bounds error.  I couldn't find docs on how to do this so I'm working blind.  Anyone have a hint?
thanks!
-Nic

code follows

Code: [Select]
public class UI : MonoBehaviour {
public tk2dUILayoutContainerSizer healthUIContainerSizer;
// Use this for initialization
void Start () {
AddMaxHealth();
}

// Update is called once per frame
void Update () {

}
    void AddMaxHealth()
{
GameObject go = (GameObject)Instantiate(Resources.Load("UI/HealthBarLength"));
tk2dUILayout layout = go.GetComponentInChildren<tk2dUILayout>();
//layout.layoutItems[0];
//tk2dUILayoutItem item = go.GetComponentInChildren<tk2dUILayoutItem>();
healthUIContainerSizer.AddLayoutAtIndex(layout,layout.layoutItems[0],1);
}
}
Title: Re: How to add layout to tk2dUILayoutContainerSizer in code dynamically?
Post by: unikronsoftware on May 14, 2014, 01:13:25 pm
Hi,

Please check the tk2dUIDemo5Controller (and demo 5). That illustrates how you can create lists dynamically, with and without layouts.