hi,
one easy approach would be to use a fixed array… like in this screen you have 5 slots. when you create your inventory slots from left to right, 0 if left, 4 is right…
you could now use a simple function which updates your slot items based on an array of SlotLength, lets call it ItemArrayForSlots…
now your slots have the same order as the ItemArrayForSlots (left to right)
for your slots you can GetChildAtIndex(x) from the Grid or have a SlotArray and use the same ID for them…
use a FOR loop and then simple set on change
GetChildAtIndex(x).ItemImage = ItemArrayForSlots [x].ItemImage
or
SlotArray[x].ItemImage = ItemArrayForSlots [x].ItemImage
because index 0 will always be left, if you add a new item and update your slots then the new item will be left and the others get shift to the right…
you can also add a new item to the end to inverse it
what i forgot…
you can have more items, id stays the same and if you start from top left corner you can easily get your grid position ( in case you have more rows than 1
gridX = ArrayIndex % GridColumns
gridY = ArrayIndex / GridColumns
you can use a int point or have 2 integer for it…
i hope that makes sense… when i am back in the evening i can make a screenshot
cheers