Hey!
So I’m currently in a state of confused mixed with rage… I have a ‘working’ inventory system where if you pick up items (or chop a tree for instance) you get the items and it all works. So to easier explain this to you without posting the whole code my problem is if you already have say, 3 logs in the inventory and pick up a whole new item (Like a stone) logs reset to 1 and I get 1 stone.
I think I narrowed it down to 1 of 2 for loops but at this point, I’m going nuts and don’t understand why it resets
This is the one i use to update the UI.
UpdateUI
void UpdateUI ()
{
// Loop through all the slots
for (int i = 0; i < slots.Length; i++)
{
if (i < inventory.items.Count) // If there is an item to add
{
slots[i].AddItem(inventory.items[i]); // Add it
}
else
{
// Otherwise clear the slot
slots[i].ClearSlot();
}
}
}
or this one where I add the item to the inventory
Add(Item item)
public bool Add (Item item)
{
// Don't do anything if it's a default item
if (!item.isDefaultItem)
{
if (items.Contains(item)) //if you have more then 1 in inv
{
for (int i = 0; i < slots.Length; i++)
{
if (slots[i].ItemName == item.name)
{
slots[i].weight = slots[i].weight + 1;
slots[i].quantity.text = slots[i].weight.ToString();
return true;
}
else
{
Debug.Log("broke boi");
}
}
}
if (items.Count >= space) //Out of space
{
Debug.Log("Not enough room.");
return false;
}
items.Add(item); // Add item to list
return true;
}
Yes, code might not be most optimized but the goal is to make it work first Need any more info just ask.
Thanks in advance!