public void UseItem() { if (inventory.GetItemCount() > 0) { //Get the item to consume from inventory itemToConsume = inventory.TakeItem(); switch (itemToConsume.name.ToUpper()) { case "SPEEDBOOST": StartCoroutine(SpeedBoost()); break; case "SPEEDREDUCTION": StartCoroutine(SpeedReduction()); break; case "INVERTCONTROL": StartCoroutine(InvertControl()); break; case "BOMB": Bomb(); break; } print("ITEM USED"); //increment jugs consumed player.jugsConsumed += 1; } else { print("INVENTORY EMPTY"); } }
//Return the first item from the list and remove it public PickupInventoryItem TakeItem() { PickupInventoryItem firstItem = inventoryItems[0]; inventoryItems.Remove(inventoryItems[0]); inventoryChangeEvent.Raise(); return(firstItem); }
//Add an item to the list public bool addItem(PickupInventoryItem item) { if (inventoryItems.Count < maxInventory.Value) //if inventory is not full, add item and raise itemadded event { inventoryItems.Add(item); inventoryChangeEvent.Raise(); return(true); } else { return(false); } }
//Throw the first item in the inventory to the right public void ThrowItemRight() { if (canThrow && inventory.GetItemCount() > 0) { //print("CHUCKED RIGHT"); StartCoroutine("ThrowTimer"); itemToThrow = inventory.TakeItem(); GameObject currentWeapon = Instantiate(weaponPrefab, rightWeaponSpawn.transform.position, Quaternion.identity); //Instatiate a weapon pefab currentWeapon.GetComponent <Weapon>().SetWeaponType(itemToThrow); //Set the weapon prefab type //currentWeapon.GetComponent<Rigidbody>().AddForce(new Vector3(throwForceX.Value, throwForceY.Value, 0), ForceMode.Impulse); //Apply force to the prefab - to the right currentWeapon.GetComponent <Rigidbody>().AddForce(CalculateDirectionRight(), ForceMode.Impulse); //increment jugs thrown player.jugsThrown += 1; } }
//Set the weapon type public void SetWeaponType(PickupInventoryItem item) { print("I AM A " + item.name); weaponType = item; }