I am trying to create an inventory box not unlike the original resident evil games, I can put items in with no issues. My problems occur when i try to remove an item. the item will be removed from the box and added to my inventory but for some reason the item will spawn at the bottom of the list.
(there is a secret extra slot that the guns hiding in).
[74599-p1.png*_|74599]
[74600-p2.png*_|74600]
if (inventory.ItemStorage [slotNumber].itemName == null )
{
item = null;
itemAmmo = 0;
ItemId = 0;
itemIcon.enabled = false;
itemIcon.sprite = null;
ammoSet = false;
itemCount.count = 0;
itemNameText.text = "";
}
if (inventory.ItemStorage[slotNumber].itemName != null)
{
item = inventory.ItemStorage[slotNumber];
itemIcon.enabled = true;
itemIcon.sprite = inventory.ItemStorage[slotNumber].itemIcon;
itemNameText.text = item.itemName;
itemCount.count = item.itemAmmo;
Debug.Log (slotAmmo + " " + slotNumber);
if (item.itemType == Items.ItemType.Key)
{
itemCount.itemTotal.text = "";
ammoSet = true;
}
if (ammoSet == false)
{
itemAmmo = myData.ammo;
ammoSet = true;
}
}
else
{
itemIcon.enabled = false;
if (itemCount.count == 0)
{
itemCount.itemTotal.text = "";
}
}
}
public void OnSubmit()
{
inventory.ItemStorage.Remove(item);
inventory.itemAmmo = itemCount.count;
inventory.removeFromStorage = true;
inventory.removeFromStorageAmmoSet = true;
inventory.addItem (item.itemID);
//inventory.removeItemFromStorage (item.itemID);
//inventory.slotNumber = slotNumber;
}
}
When the slot is clicked it will run the OnSubmit function. I have tried the .Remove, .RemoveAt and making the slot null all to no avail.
public void addItem(int id)
{
for (int i = 0; i < dataBase.items.Count; i++)
{
if (dataBase.items *.itemID == id)*
-
{*
_ Items item = dataBase.items ;_
* addToEmptySlot (item);*
* break;*
* }*
* }*
* }*
void addToEmptySlot(Items item)
* {*
* for (int i = 0; i < Item.Count; i++) {*
_ if (Item .itemName == item.itemName && item.itemType == Items.ItemType.Ammo) {
* stackAmmo (item);
stacked = true;
break;
}
}*_
* for (int i = 0; i < Item.Count; i++)*
* {*
_ if (Item .itemName == null && removeFromStorage == false && stacked == false)
* {*
Item = item;
//Item .itemAmmo = itemAmmo;_
* Item.Add (item);*
* break;*
* }*
_ else if (Item .itemName == null && removeFromStorage == true && stacked == false)
* {
//ItemStorage.Remove (item);
Item = item;
defaultInt = Item .itemAmmo;
Item .itemAmmo = itemAmmo;
Debug.Log (Item .itemAmmo);
Item.Add (item);
//ItemStorage.Remove (item);*
//Item .itemAmmo = defaultInt;_
* removeFromStorage = false;*
* break;*
* }*
* }*
* stacked = false;*
* }*
I have spent a day and as many fixes as I could conjure, sorry if the post doesn’t adhere to standards, this is my first one.
So bluntly, when i click the storage slot the item should enter my inventory and be completely removed from storage.
If you need more info, simply ask and thanks in advance :).
*
*