- Home /
Question by
mike1997 · Jul 06, 2016 at 07:25 AM ·
scripting problemscrollview
Add Items to Scroll view though code
Could some one please help me find some code that shows how to add prefab items to scroll view though code.
Also manage changes to items in the scroll view.
Mike
Comment
Answer by mike1997 · Jul 03, 2016 at 08:04 AM
I figured it out, here is a simple example
//Cards is an array of data
for (int i = 0; i < Cards.Count; i++)
{
//ItemGameObject is my prefab pointer that i previous made a public property
//and assigned a prefab to it
GameObject card = Instantiate(ItemGameObject) as GameObject;
//scroll = GameObject.Find("CardScroll");
if (ScrollViewGameObject != null)
{
//ScrollViewGameObject container object
card.transform.SetParent(ScrollViewGameObject.transform,false);
}
}
Your answer