hello I have a doubt, how could I rearrange the children of the container so that they are shown in random order in x? or instantiate them inside the container but randomly? Thank you!
Need it just on start
Defined children in container with horizontal layout.
Sorry my english is bad D:
You could use Transform.SetSiblingIndex with a random value between 0 and the number of child objects in the parent container.
Example:
public class Example : MonoBehaviour {
GameObject[] childObjects;
void SomeMethod() {
int childrenLength = childObjects.Length;
for(int i = 0; i < childrenLength; i++) {
Instantiate(childObjects[i], transform);
}
foreach(Transform child in transform) {
int randomIndex = Random.Range(0, childrenLength - 1);
child.SetSiblingIndex(randomIndex);
}
}
}
1 Like
just fantastic! thank you so much genius