private void Update() { if (usable != null) { if (usable.active == false) { usable = null; } } //hold usable if (usable != null && usable.hold == false && Input.GetKeyDown(KeyCode.E)) { usable.Use(); } //not hold usable if (usable != null && usable.hold == true && Input.GetKey(KeyCode.E)) { usable.Use(); } if (usable == null) { useText.SetActive(false); } }
public void UseItem() { if (storedItem != null) { storedItem.Use(fireTurret); } }
void Interact() { if (objectToUse != null) { isUsingObject = true; objectToUse.Use(this); } }
private void AttemptToUse(Collider other) { Usable usable = other.gameObject.GetComponent <Usable>(); if (usable) { usable.Use(); } }
// Update is called once per frame void Update() { //use button is E if (Input.GetButtonDown("Use")) { if (PickUp.IsHoldingObject()) { Usable usable = PickUp.HeldObject().GetComponent <Usable>(); if (usable != null) { usable.Use(); Debug.Log("use Pressed"); } } } }
void UpdateUse(float dT) { bool checkUse = controls.IsUse(); if (checkUse) { if (liftTarget) { Tool tool = liftTarget.GetComponent <Tool>() as Tool; if (tool) { tool.user = this; tool.Use(); return; } } if (useTarget != null) { if ( DistanceSquaredTo(useTarget.transform.position) < useDistanceSquared && IsFacing(useTarget.transform.position, useAngle) ) { useTarget.Use(dT); UpdateLookAtPosition(useTarget.transform.position, dT, turnSpeed); } else { useTarget = null; } } if (useTarget == null) { Usable curTarget = GetClosestUsable(useDistanceSquared); if (curTarget) { useTarget = curTarget; } } } else { useTarget = null; } }
private void UseItem() { Item item = data.inventory.content[data.currentItem].item; if (item is Weapon) { data.player.EquipWeapon((Weapon)item); } if (item is Armor) { data.player.EquipArmor((Armor)item); } if (item is Throwable) { Throwable t = (Throwable)item; data.inventory.content[data.currentItem].count -= 1; // == 0 for potential abuse with items that have a count of < 0 to allow easier unlimited use items bool temp = t.Use(); if (data.inventory.content[data.currentItem].count == 0 && temp) { data.inventory.content.RemoveAt(data.currentItem); data.currentItem = -1; } data.player.actions--; QuitInventory(); } if (item is Usable) { Usable u = (Usable)item; data.inventory.content[data.currentItem].count -= 1; // == 0 for potential abuse with items that have a count of < 0 to allow easier unlimited use items if (data.inventory.content[data.currentItem].count == 0) { data.inventory.content.RemoveAt(data.currentItem); data.currentItem = -1; } u.Use(); data.player.actions--; QuitInventory(); } }
public void UseButtonClicked() { Usable u = (Usable)currentItem; u.Use(); cooldown[u.GetType()] = u.cooldown + 1; availability[u.GetType()] = false; if (typeof(Consumable).IsInstanceOfType(currentItem)) { Consumable c = (Consumable)currentItem; if (c.amount == 0) { Remove(c); ClearSelection(); } amountText.GetComponent <TextMeshProUGUI>().text = c.amount.ToString(); } }
void UseItem() { if (PlayerManager.Instance.playerDisabled) { return; } itemUsing = PlayerManager.Instance.PlayerUsableList[PlayerManager.Instance.usableSelected]; if (itemUsing == null) { return; } if (itemUsing.ammount <= 0) { Debug.Log("Cantidad: " + itemUsing.ammount); return; } itemUsing.Use(); Debug.Log("Ha sido usado el item: " + itemUsing.itemName + ". En la posición: " + PlayerManager.Instance.usableSelected + " del array"); }
//player actions private void PlayerActions() { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); RigidBodyController controller = GetComponentInParent <RigidBodyController>(); controller.Locomote(new Vector3(horizontal, 0, vertical)); controller.Rotate(); if (Input.GetKeyDown(KeyCode.Space)) { controller.Jump(); } if (Input.GetMouseButtonDown(0)) { //become other player on left click CreateRay(); } if (Input.GetKeyDown(KeyCode.C)) { if (CamMode == 1) { CamMode = 0; } else { CamMode++; } StartCoroutine(CamChange()); } if (Input.GetKeyDown(KeyCode.U)) { if (actionPickup && actionPickup.IsHoldingObject()) { Usable usable = actionPickup.HeldObject().GetComponent <Usable>(); if (usable) { usable.Use(); } } } if (Input.GetKeyDown(KeyCode.I)) { //call spawn function } if (Input.GetKeyDown(KeyCode.P)) { //call pickup function actionPickup = GetComponentInParent <Pickupper2>(); actionPickup.PickUp(); } if (Input.GetKeyDown(KeyCode.E)) { //call eat function actionEat = GetComponentInParent <Eat>(); actionEat.EatFood(); } if (Input.GetKeyDown(KeyCode.T)) { if (actionPickup && actionThrow && actionPickup.IsHoldingObject()) { actionThrow.ThrowObject(); } } //... more actions }
//player actions private void PlayerActions() { float horizontal = Input.GetAxis("Horizontal"); float vertical = Input.GetAxis("Vertical"); RigidBodyController controller = GetComponentInParent <RigidBodyController>(); controller.Locomote(new Vector3(horizontal, 0, vertical)); controller.Rotate(); if (Input.GetKeyDown(KeyCode.Space)) { controller.Jump(); } if (Input.GetMouseButtonDown(0)) { //become other player on left click CreateRay(); } if (Input.GetKeyDown(KeyCode.C)) { if (CamMode == 1) { CamMode = 0; } else { CamMode++; } StartCoroutine(CamChange()); } if (Input.GetKeyDown(KeyCode.U)) { if (actionPickup && actionPickup.IsHoldingObject()) { Usable usable = actionPickup.HeldObject().GetComponent <Usable>(); if (usable) { usable.Use(); } } } if (Input.GetKeyDown(KeyCode.I)) { //checks for the actionpickup script and if it is holding an object if (actionPickup && actionPickup.IsHoldingObject()) { //check if the picked up item has a spawner script //get the spawner script in the children component of pickupper script actionSpawn = actionPickup.GetComponentInChildren <Spawner>(); //call spawn function actionSpawn.Spawn(); } } if (Input.GetKeyDown(KeyCode.P)) { //call pickup function actionPickup = GetComponentInParent <Pickupper>(); actionPickup.PickUp(); } if (Input.GetKeyDown(KeyCode.L)) { dropItem = GetComponentInParent <DropItem>(); dropItem.DropHeldObject(); } if (Input.GetKeyDown(KeyCode.E)) { //call eat function actionEat = GetComponentInParent <Eat>(); actionEat.EatFood(); } if (Input.GetKeyDown(KeyCode.T)) { /* * actionThrow = GetComponentInParent<Throw>(); * actionThrow.ThrowObject(); */ } //... more actions }
void InstantActivateItem(Usable ItemUsable) { ItemUsable.launcher = _player; ItemUsable.Use(fireTurret); }