public void addSlotToContainer(inventory inventory, int slotID, float x, float y, int slotSize) { // retrieve parent, slot, information on itself; GameObject spawnedSlot = Object.Instantiate(inventoryManager.INSTANCE.slotPrefab); inventorySlot slot = spawnedSlot.GetComponent <inventorySlot>(); RectTransform slotRT = slot.GetComponent <RectTransform>(); slot.setSlot(inventory, slotID, this); // attaches slot to the main container for inventory spawnedSlot.transform.SetParent(spawnedContainerPrefab.transform); spawnedSlot.transform.SetAsFirstSibling(); // sets the anchor position so it can reference the object slotRT.anchoredPosition = new Vector2(x, y); // sets the localpos to 0 z because otherwise it seems to fly around and it's a good backup slotRT.localPosition = new Vector3(slotRT.localPosition.x, slotRT.localPosition.y, 0); // sets the scale of each slot - scale is more like zoom slotRT.localScale = Vector3.one; // sets the size of each slot slotRT.sizeDelta = Vector2.one * slotSize; // add it to the container slots.Add(slot); }