public void BuyItem() { InventorySystem Inventory = GameObject.Find("Inventory").GetComponent <InventorySystem>(); if (!Inventory) { Debug.LogError("Inventory Not Found"); return; } if (SelectItem == int.MaxValue) { Debug.LogError("don't Selection Item"); return; } int[] Inven_ItemID = Inventory.InventoryItemSearch(); float requireGold = ItemList[SelectItem].Gold; float Gold = Inventory.GetGold(); bool IsEmptySlot = false; for (int i = 0; i < Inven_ItemID.Length; i++) { if (Inven_ItemID[i] == int.MaxValue) { IsEmptySlot = true; break; } } if (ItemList[SelectItem].itemTag == Scriptable_Item.tag_item.equipment) { if (ItemList[SelectItem].ItemForCraft == 0) { if (!IsEmptySlot) { //error } if (requireGold < Gold) { Inventory.Equipitem(ItemList[SelectItem], requireGold); } else { // error } } else { requireGold = CalculationPrice(Inven_ItemID, SelectItem); IsEmptySlot = false; for (int i = 0; i < Inven_ItemID.Length; i++) { if (Inven_ItemID[i] == int.MaxValue || Inven_ItemID[i] == int.MinValue) { IsEmptySlot = true; break; } } if (IsEmptySlot && requireGold < Gold) { Inventory.Equipitem(ItemList[SelectItem], requireGold); } else { //error } } } else // { if (requireGold > Gold) { //error Debug.Log("RequireGold"); return; } int ItemSlotNum = int.MaxValue; for (int i = 0; i < Inven_ItemID.Length; i++) { if (ItemList[SelectItem].Id == Inven_ItemID[i]) { ItemSlotNum = i; break; } } if (ItemSlotNum != int.MaxValue && Inventory.ExpendableItemCount(ItemSlotNum) < ItemList[SelectItem].Overlap) { Inventory.Expendableitem(ItemSlotNum, requireGold); } else if (ItemSlotNum == int.MaxValue && IsEmptySlot) { Inventory.Equipitem(ItemList[SelectItem], requireGold); } else { //error max Debug.Log("Error"); } } }