/** * ApplyPlaceClaymoreTrap() * * Place traps on input */ public void ApplyPlaceTrap(int TRAP_TYPE) { if (!GetComponent <MenteBacata.ScivoloCharacterControllerDemo.SimpleCharacterController>().isGrounded) { return; } if (TrapInventory.trapsInInventoryCount == 0) { Debug.Log("No traps to place."); return; } // Check inventory for a trap of the type if (TRAP_TYPE == 0 && TrapInventory.HasTrapsOfType <ClaymoreTrap>()) { Debug.Log("Placing a claymore trap!"); GameObject.Instantiate(claymoreTrap, placeTrapAim.transform.position, Quaternion.identity); --TrapInventory.trapsInInventoryCount; int indexTrap = TrapInventory.traps.FindIndex(t => t.TrapID == 1); if (indexTrap > -1) { Debug.Log("Removing claymore trap"); TrapInventory.traps.RemoveAt(indexTrap); // Re-update UI UIOnPlacedClaymoreTrap(); } } }
void GetClaymoreTrap() { // Add to inventory if not full already if (TrapInventory.trapsInInventoryCount < TrapInventory.TRAP_MAX_AMOUNT) { Debug.Log("Adding a claymore trap to inventory"); ++TrapInventory.trapsInInventoryCount; // This uses the Scriptable Object Constructor instead of invoking "new ClaymoreTrap()" ClaymoreTrap claymoreTrap = ScriptableObject.CreateInstance <ClaymoreTrap>(); TrapInventory.AddToInventory(claymoreTrap); // Update UI via event UIOnBuyClaymoreTrap(); } else { Debug.Log("Inventory full."); } }