//Checks for input => calls Drop Item Event. void CheckForDrop() { if (Input.GetButtonDown("Drop item")) { itemMaster.CallEventDropItem(0, null, 0); inventoryMaster.CallEventRemoveFromInventory(inventoryMaster.selectedInventorySlot, null); } }
//if selected slot isn't empty //Call dropItem event //Call remove from inventory event public void CallEventDropItem(int refNumber, GameObject item, int selectedIndex) { selectedIndex = inventoryMaster.selectedInventorySlot; if (inventoryMaster.inventory[inventoryMaster.selectedInventorySlot] != null) { EventDropItem(0, inventoryMaster.inventory[inventoryMaster.selectedInventorySlot], selectedIndex); inventoryMaster.CallEventRemoveFromInventory(selectedIndex, null); } else { Debug.Log("Can't drop item from chosen inventory slot: Empty"); } }
void CheckForUse() { //Checks if the currently selected slot isn't empty if (inventoryMaster.inventory[inventoryMaster.selectedInventorySlot] == null) { return; } //Checks for input //if the currently selected slot is interactable it checks for an interactable world object --> if it found an interactable go --> call interact event on the go //else calls use item event if (Input.GetButtonDown("Interact")) { print("Trying to interact or use item"); if (inventoryMaster.inventory[inventoryMaster.selectedInventorySlot].GetComponent <Item_Master>().isInteractable) { print("Item is interactable. checking raycast"); if (Physics.Raycast(transform.position, transform.forward, out hit, range, interactableLayer)) { print("Found interactable with name: " + hit.transform.name); hit.transform.GetComponent <Interactable_Master>().CallEventPlayerInteracts(); inventoryMaster.CallEventRemoveFromInventory(inventoryMaster.selectedInventorySlot, null); } } else { print("Item isn't interactable. Using item"); //Instantiates GO, calls use event on GO Transform temp; Instantiate(inventoryMaster.inventory[inventoryMaster.selectedInventorySlot], useAbleItemParent, true); inventoryMaster.CallEventRemoveFromInventory(inventoryMaster.selectedInventorySlot, null); temp = useAbleItemParent.GetChild(0); temp.GetComponent <UseAble_Master>().CallEventUseItem(); temp.GetComponent <Item_Master>().CallEventItemDeath(); } } }
public void CallEventPlayerInteracts() { int amountOfRightItems = 0; for (int i = 0; i < 2; i++) { for (int x = 0; x < requiredItems.Count; x++) { if (inventoryMaster.inventory[i] == requiredItems[x]) { amountOfRightItems++; inventoryMaster.CallEventRemoveFromInventory(i, null); } } } if (amountOfRightItems == requiredItems.Count) { EventPlayerInteracts(); } }