Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: jmansa on August 11, 2014, 10:31:28 AM

Title: Generate ScrollView from c#
Post by: jmansa on August 11, 2014, 10:31:28 AM
I am trying to figure out how to generate an scrollview from c#. I have made an GameObject as ScrollView and attached an grid. I have then made an prefab sprite which I want to copy/clone into my scrollview, but it is not working. Is there anything I am missing?

Here is how I have done so far:

  1. public GameObject listGrid;
  2. public GameObject listItem;

These 2 holds the grid object and the prefab.

  1. for(int i = 0;i < 3;i++){
  2.         GameObject insObj = Instantiate(listItem) as GameObject;
  3.         insObj.name = "listobject"+i;
  4.         insObj.SetActive(true);
  5.         insObj.transform.parent = listGrid.transform;
  6.         insObj.transform.localScale = new Vector3(1,1,1);
  7. }

This generates the list items, but they do not get in order below each other... The all is placed the same place?!?!

Hoping for help and thanks in advance :-)
Title: Re: Generate ScrollView from c#
Post by: Ajvass on September 24, 2014, 03:03:53 AM
After for cycle try this code:
  1. UIGrid grid = listGrid.GetComponent<UIGrid>();
  2. grid.Reposition();
  3.