- Home /
How to offset transform of each item placed.
This is a section of my code I am using for a 3d inventory system I created. I am stuck on a problem right now about how to offset the transform of each stick placed after the first one. Assume that the first stick is already placed and I would like the next for in this section to be placed next to it by a some variable. This problem is probably easier than I am making but any help is greatly appreciated.
if(iStickCount > 1 && iStickCount % 5 != 0)
{
if(itemPlacedInStack == false)
{
foreach (Transform child in invSlots[i].transform)
{
int childCount = child.transform.parent.childCount;
if(childCount < 5)
{
if(child.transform.name == "inv_Stick")
{
Vector3 childPos = child.transform.position;
Vector3 transPos = transform.position;
transform.parent = invSlots[i].transform;
transPos = childPos;
//transPos.x = childPos.x +1;
itemPlacedInStack = true;
return;
}
}
}
}
}
do you want to offset each individual stick? or you are you going for a $$anonymous$$e craft style storage(after 64 stick a new stack gets created?). OR like other RPS one a stack reaches its maximum reject any new additions? its hard to make out what your trying to do.
anyway the general idea is to collect all of your items into of an array(I'm assu$$anonymous$$g its invSlots) then run a loop to the amount of items in the inventory... each loop, you want to do whatever is needed, if your items don't stack you can offset it each loop, if they don't, only offset it every X times... making sure that you check that your adding the correct items to the stack( you can't have a stick and a bean bag in the same stack)
could you tell me in greater detail what you want help with?