/// <summary> /// Throws the grabbed item. /// </summary> /// <param name="dir">direction of throw</param> protected virtual void throwItem() { if (grabbedItem != null) { grabbedItem.transform.parent = null; grabbedItem.getRigidBody().isKinematic = false; grabbedItem.setIsPicked(false); grabbedItem.setIsUsed(true); grabbedItem.GetComponent <ThrowableItem>().onThrow(); float throwForce; if (chargeAmount > 0) { throwForce = grabbedItem.getVelocity() + (chargeAmount * maxThrowForce / 2); chargeAmount = 0; } else { throwForce = grabbedItem.getVelocity(); } switch (throwDirection) { case Utilities.direction.Up: grabbedItem.getRigidBody().AddForce(new Vector2(0, throwForce), ForceMode2D.Impulse); break; case Utilities.direction.Down: grabbedItem.getRigidBody().AddForce(new Vector2(0, -throwForce), ForceMode2D.Impulse); break; case Utilities.direction.Left: grabbedItem.getRigidBody().AddForce(new Vector2(-throwForce, 0), ForceMode2D.Impulse); break; case Utilities.direction.Right: grabbedItem.getRigidBody().AddForce(new Vector2(throwForce, 0), ForceMode2D.Impulse); break; case Utilities.direction.UpLeft: grabbedItem.getRigidBody().AddForce(new Vector2(-throwForce, throwForce), ForceMode2D.Impulse); break; case Utilities.direction.UpRight: grabbedItem.getRigidBody().AddForce(new Vector2(throwForce, throwForce), ForceMode2D.Impulse); break; case Utilities.direction.DownLeft: grabbedItem.getRigidBody().AddForce(new Vector2(-throwForce, -throwForce), ForceMode2D.Impulse); break; case Utilities.direction.DownRight: grabbedItem.getRigidBody().AddForce(new Vector2(throwForce, -throwForce), ForceMode2D.Impulse); break; } grabbedItem.GetComponent <ThrowableItem>().setDirection(throwDirection); grabbedItem = null; hasItem = false; } if (isGrounded) { state = Utilities.state.Idle; } else { state = Utilities.state.Air; } }
/// <summary> /// Metodo que maneja el recibimiento de inputs dentro del juego /// </summary> void Inputs() { // Interaccion con el boton de interactuar y un objeto interactuable if (canInteract && Input.GetButton("Fire1")) { if (currentItem != null) { if (currentItem.type == InteractableObjectType.Food) { playerInverntoryControlerReference.AddFoodRation(); Destroy(currentItem.gameObject); } else if (currentItem.type == InteractableObjectType.Item) { playerInverntoryControlerReference.AddItem(currentItem); } else if (currentItem.type == InteractableObjectType.LockedDoor) { if (CheckDoor()) { currentRoomDetector = currentItem.GetComponent <RoomDetectorContoller>(); canInteract = false; canGoDoor = true; Destroy(currentItem); } else { canInteract = false; //No tienes la llave papu } } } else if (doorwayLockDetector != null) { int posInventory = CheckDoorway(); if (CheckDoorway() != -1) { canInteract = false; doorwayLockDetector.DoEvents(); List <PickableItemInfo> currentInventory = playerInverntoryControlerReference.GetInventory(); //currentInventory[posInventory]. } else { canInteract = false; } } } // parte que maneja el entrar a una puerta desbloqueada o que no tenia seguro double horizontalMove = Input.GetAxis("Horizontal"); double verticalMove = Input.GetAxis("Vertical"); enterDoor(horizontalMove, verticalMove); }
[SerializeField] private Transform handTransform; //Should also be a child of the player gameobject. This needs to be animated for the keyframes that move the hand void Update() { if (carryingItem && Input.GetMouseButtonDown(1)) { pickedUpItem.transform.SetParent(null); pickedUpItem.transform.position = spawnPosition.position; pickedUpItem.GetComponent <Rigidbody2D>().AddForce(transform.right * throwingForce.x + transform.up * throwingForce.y); pickedUpItem = null; } }
public override void InteractWith(PlayerController player) { Inventory inv = player.GetComponent <Inventory>(); PickableItem carriedItem = inv.ReleaseItem(); QuestItem questItem = carriedItem.GetComponent <QuestItem>(); if (questItem == null) { inv.GrabItem(carriedItem); Debug.LogFormat("This {0} is useless for the ritual.", carriedItem.name); } else { questItem.transform.parent = this.transform; GameObject.Destroy(questItem); if (NextStep() == 0) { Debug.LogWarning("WE HAVE A WINNER"); } } }
void handleItem(PickableItem item) { if(player.ActiveAbilities.onItemPickup != null) player.ActiveAbilities.onItemPickup (item); if (item.GetComponent<Weapon>()) { if (player.CurrentWeapon) player.CurrentWeapon.destroy(); player.useWeapon(item.GetComponent<Weapon>()); } else if(item.GetComponent<Bonus>()) { if (item.GetComponent<Bonus>().Duration != 0) player.GetComponent<BonusManager>().handleBonus(item.GetComponent<Bonus>()); else item.GetComponent<Bonus>().activate(); } else Debug.LogError("ItemsPickup : Unrecognized PickableItem!"); }