I’m trying to make a script that instantiates a slot prefab into a UI Panel multiple times. After instantiated, the slots need to be given a parent.
This is a snippet of my code:
function createInventory () {
for (var i: int = 0; i < 10; i++) {
var Clone = Instantiate(slotObject, inventoryParent.transform.position, inventoryParent.transform.rotation);
Clone.transform.parent = inventoryParent.transform;
}
}
It only seems to be instantiating one slot at the moment. What can I do to fix this? Thanks in advance!
Hi,
First I think you don’t need to set the same position and rotation as inventoryParent to Clone because Clone is a child of inventoryParent.
for (var i: int = 0; i < 10; i++) {
var Clone = Instantiate(slotObject);
Clone.transform.SetParent(inventoryParent.transform, false);
}
Have you added a Layout Group to inventoryParent ? If no, maybe your Clones are all at the same position and rotation. Try a VerticalLayoutGroup for example 
And if your Clones size shrinks to 0, add a Layout Element to your prefab to define a min and max size.