so i’ve been working on this tutorial (Make An RPG: Inventory System Part 2 - YouTube) everything seems fine until the end of this video, when i want to test it. instead of generating 25 tiles it justs generates one big tile/itemSlot filling up more hten screenspace can handle. i can still use it and everything, but the size just isn’t right.
So i tried dragging the prefab manually into the scene, but the tile is still gigantic. So i dragged the correct looking itemslot gameobject onto the prefab to “update” it. Still, i get this giant object (even the picture is missing)
What am i missing here ?
I assume that you are Instantiating the ItemSlot prefab by code.
A simple hack is to create a Panel UI inside the InventoryWindow,
this will be the container for all ItemSlots
-resize and position the Panel UI, add a Canvas Group to the Panel UI, and add a Grid Layout Group to the Panel UI, and tweak the Grid Layout Group values such as Cell Size to X: 64 Y:64
-on your script Instantiate the ItemSlot prefab on the Panel.
with this, you will not need to do a for loop on rows and columns just to draw the ItemSlots on the correct position, the Grid Layout Group can handle it for you.
another way is this, on your script after you instantiate the ItemSlot
// This will instantiate your Item Slot prefab on the scene
GameObject slot = (GameObject)Instantiate(slotPrefab);
//parentTransform, is the Transform where you want the ItemSlot to be spawned.
// the false is the world position wont stay.
slot.transform.SetParent(parentTransform, false);
//last set the scale of the slot to 1
slot.GetComponent().localScale = new Vector3(1, 1, 1);
Thanks alot!!
i was using a similar code and in slot.transform.setparent(parentTransform, false) i missed the false.
now it looks muuuuch better. Thanks!