Hello Guest

Author Topic: How to add layout to tk2dUILayoutContainerSizer in code dynamically?  (Read 4026 times)

soulareus

  • Newbie
  • *
  • Posts: 2
    • View Profile
      

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);
}
}

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Hi,

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