Inventory.checkIfItemAllreadyExist C# (CSharp) Method

checkIfItemAllreadyExist() public method

public checkIfItemAllreadyExist ( int itemID, int itemValue ) : bool
itemID int
itemValue int
return bool
    public bool checkIfItemAllreadyExist(int itemID, int itemValue)
    {
        updateItemList();
        int stack;
        for (int i = 0; i < ItemsInInventory.Count; i++)
        {
            if (ItemsInInventory[i].itemID == itemID)
            {
                stack = ItemsInInventory[i].itemValue + itemValue;
                if (stack <= ItemsInInventory[i].maxStack)
                {
                    ItemsInInventory[i].itemValue = stack;
                    GameObject temp = getItemGameObject(ItemsInInventory[i]);
                    if (temp != null && temp.GetComponent<ConsumeItem>().duplication != null)
                        temp.GetComponent<ConsumeItem>().duplication.GetComponent<ItemOnObject>().item.itemValue = stack;
                    return true;
                }
            }
        }
        return false;
    }

Usage Example

Example #1
0
 // Update is called once per frame
 void Update()
 {
     if (_inventory != null && UserControl.PickupItem)
     {
         float distance = Vector2.Distance(new Vector2(this.gameObject.transform.position.x, this.gameObject.transform.position.y), new Vector2(_player.transform.position.x, _player.transform.position.y));
         print("distance: " + distance);
         if (distance <= 1.3)
         {
             sceneManager.GetComponent <MySceneManager>().removeFromGearList(this.gameObject);
             bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
             if (check)
             {
                 Destroy(this.gameObject);
             }
             else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
             {
                 _inventory.addItemToInventory(item.itemID, item.itemValue);
                 _inventory.updateItemList();
                 _inventory.stackableSettings();
                 Destroy(this.gameObject);
             }
         }
     }
     if (_inventory != null && UserControl.GetGearsBack)
     {
         addItemToInv(item.itemID, item.itemValue);
     }
 }
All Usage Examples Of Inventory::checkIfItemAllreadyExist