public override void OnPickUp(PlayerItemPickUpData data) { // Get Item Reference WeaponItem weaponItem = Item as WeaponItem; // Spawn Item if (Item.gameObject.IsPrefab()) { weaponItem = ItemDB.Inst.SpawnItem(Item.GetType()).GetComponent <WeaponItem>(); } // Add To Inventory if (PlayerInventoryManager.inventory.TryUpgradeItem(weaponItem.GetType()) || PlayerInventoryManager.weaponHotbar.TryUpgradeItem(weaponItem.GetType())) { Destroy(weaponItem.gameObject); goto EXIT; } if (PlayerInventoryManager.weaponHotbar.TryAddItem(weaponItem, PlayerInventoryManager.weaponHotbar.CurSlot)) { goto EXIT; } if (PlayerInventoryManager.weaponHotbar.TryAddItem(weaponItem)) { goto EXIT; } if (PlayerInventoryManager.inventory.TryAddItem(weaponItem)) { goto EXIT; } return; EXIT: Destroy(gameObject); }
protected override void Update() { base.Update(); if (GameState.isPaused || isDead) { return; } // MOVEMENT moveInput = !ignoreMoveInput ? new Vector2(GameState.moveAxis.GetAxis(), 0f).normalized.x : 0f; if (isOnGround) { if (GameState.jumpAction.GetDown() && isOnGround && !ignoreMoveInput) { velocity.y = jumpForce; } } else { if (velocity.y > 0f && !ignoreMoveInput) { if (GameState.jumpAction.GetUp()) { velocity.y *= 0.7f; } } if (!ignoreMoveInput && GameState.mainUseAction.GetDown() && mainWeaponObject && mainWeaponObject.GetType() == typeof(MeleeWeaponItem) && velocity.y > -jumpForce) { ignoreMoveInput = true; velocity.y *= 0f; velocity.y += 2.5f; animator.Play(anims.plunge, ((MeleeWeaponItem)mainWeaponObject).speed); } } if (currentAP <= 0f) { isAPRecharging = true; } if (isAPRecharging) { currentAP = Mathf.Clamp(currentAP + (5f * Time.deltaTime), 0f, maxAP); isAPRecharging = currentAP < maxAP; } // ITEMS if (mainWeaponObject) { mainWeaponObject.transform.position = nodes.GetPosition(0); mainWeaponObject.transform.eulerAngles = new Vector3(0f, 0f, nodes.GetAngle(0)); if (GameState.mainUseAction.GetDown() && mainWeaponObject.CanUse(this)) { mainWeaponObject.OnUse(this); } else if (GameState.mainUseAction.GetUp()) { mainWeaponObject.OnEndUse(this); } else if (GameState.mainUseAction.GetHeld()) { mainWeaponObject.OnHoldUse(this); } } if (offWeaponObject) { offWeaponObject.transform.position = nodes.GetPosition(1); offWeaponObject.transform.eulerAngles = new Vector3(0f, 0f, nodes.GetAngle(1)); if (GameState.offUseAction.GetDown() && offWeaponObject.CanUse(this)) { offWeaponObject.OnUse(this); } else if (GameState.offUseAction.GetUp()) { offWeaponObject.OnEndUse(this); } else if (GameState.offUseAction.GetHeld()) { offWeaponObject.OnHoldUse(this); } } if (GameState.shortcut1UseAction.GetDown()) { Item shortcutItem = PlayerState.instance.inventoryStock.GetItem(PlayerState.instance.shortcutItem1); if (shortcutItem && shortcutItem.CanUse(this)) { shortcutItem.OnUse(this); itemInUse = shortcutItem; } } if (GameState.shortcut2UseAction.GetDown()) { Item shortcutItem = PlayerState.instance.inventoryStock.GetItem(PlayerState.instance.shortcutItem2); if (shortcutItem && shortcutItem.CanUse(this)) { shortcutItem.OnUse(this); itemInUse = shortcutItem; } } if (GameState.shortcut3UseAction.GetDown()) { Item shortcutItem = PlayerState.instance.inventoryStock.GetItem(PlayerState.instance.shortcutItem3); if (shortcutItem && shortcutItem.CanUse(this)) { shortcutItem.OnUse(this); itemInUse = shortcutItem; } } if (GameState.shortcut4UseAction.GetDown()) { Item shortcutItem = PlayerState.instance.inventoryStock.GetItem(PlayerState.instance.shortcutItem4); if (shortcutItem && shortcutItem.CanUse(this)) { shortcutItem.OnUse(this); itemInUse = shortcutItem; } } // INTERACT if (GameState.interactAction.GetDown()) { if (!GameState.isMenuConsumingInput) { if (interactor.interactee != null && interactor.interactee.CanInteract(this)) { interactor.interactee.OnInteract(this); } } } }