Author Topic: Generate ScrollView from c#  (Read 3768 times)

jmansa

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 11
    • View Profile
Generate ScrollView from c#
« 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 :-)

Ajvass

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 1
    • View Profile
Re: Generate ScrollView from c#
« Reply #1 on: September 24, 2014, 03:03:53 AM »
After for cycle try this code:
  1. UIGrid grid = listGrid.GetComponent<UIGrid>();
  2. grid.Reposition();
  3.