Hello everyone. I have an object which has too many children, grandchildren and children of grandchildren (both more than 1000 objects). Example structure of hierarchy for that gameobject:
-Object1
-----Object2
---------Object3
---------Object4
-----Object5
---------Object6
---------Object7
-------------Object8
-----Object9 …
Also I have an UI panel and I create empty GameObject for each object in that panel at runtime. I could do that with “for” loop and set them using AddComponent and GetComponent for making them “Text”. For coordinate of objects I used;
newText.GetComponent<RectTransform> ().localPosition = new Vector3 (x, y, 0.0f);
y component increases properly, so there is no problem about that. However, each object should look like in panel just like hierarchy above. How can I set x component of coordinates of each object for that aim? I tried that;
newText.GetComponent<Text>().text = room.name;
room.name = oda.GetComponentsInChildren<Transform>()[n].gameObject.name;
if (room.GetComponentsInChildren<Transform>()[n-1].childCount > 0)
x += 25.0f;
else if (room.GetComponentsInChildren<Transform>()[n].childCount > 0)
x -= 25.0f;
n++;
(newText is a new GameObject which created at runtime)
room object is a root of that gameobject which I wrote it as a public GameObject in script. I can access each child and grandchild of room thanks to GetComponentsInChildren array. My simple if - else if condition works for first level children but for grandchildren and children of grandchildren it doesn’t. I used C# by the way. Thanks in advance.