void AttackStarted(int attackID) { if (attackID != -1) { //playerStats.Attacking(); currentAttackID = attackID; equipedWeapon.Attack(attackID); if (attackButtonPressed) { currentAttackID++; if (currentAttackID >= equipedWeapon.WeaponAttacks.Length) { currentAttackID = 0; } //Debug.Log(currentAttackID); animator.SetTrigger(equipedWeapon.AttackTriggerName); attackButtonPressed = false; } } else { equipedWeapon.Attack(attackID); } }
protected virtual void Attack() { if (m_weapon.m_isAutomatic) { if (Input.GetKey(KeyCode.Mouse0)) { m_weapon.Attack(); } } else { if (Input.GetKeyDown(KeyCode.Mouse0)) { m_weapon.Attack(); } } }
void Update() { //Check if player is in range and "E" is pressed RaycastHit hit; RaycastHit hit2; Physics.Raycast(cam.position, cam.forward, out hit, pickUpRange, pickupable); Physics.Raycast(cam.position, cam.forward, out hit2); bool isInHardcoreMode = GameManager.instance.hardcoreMode; if (!isInHardcoreMode && hit2.collider != null && !equipped && Input.GetKeyDown(KeyCode.E)) { if (hit2.collider.CompareTag("CanGrab")) { // print($"we looking at {hit2.collider.name}"); equipped = true; // print($"yes {hit.collider.gameObject.name}"); weapon = hit2.collider.GetComponent <WeaponBase>(); weapon.Pickup(); // if (hit2.collider.CompareTag("")) if (hit2.collider.gameObject.name.Contains("Gun")) { isSword = false; weapon.transform.SetParent(gunContainer); AudioManager.instance.Play("PickupSoundGun"); //pickup gun sound } else { isSword = true; weapon.transform.SetParent(swordContainer); weapon.transform.localScale = Vector3.one; AudioManager.instance.Play("PickupSoundSword"); //pickup sword sound } // weapon.transform.localPosition = Vector3.zero; // weapon.transform.localRotation = Quaternion.Euler(Vector3.zero); } } //Drop if equipped and "Q" is pressed if (equipped && Input.GetKeyDown(KeyCode.Q)) { weapon.Drop(rb.velocity); weapon.transform.SetParent(null); weapon = null; equipped = false; } //Throw if equipped and "R" is pressed if (equipped && Input.GetKey(KeyCode.R)) { weapon.Predict(swordContainer.position); } if (equipped && Input.GetKeyUp(KeyCode.R)) { weapon.Throw(rb.velocity); weapon.transform.SetParent(null); weapon = null; equipped = false; } if (equipped && isSword && Input.GetMouseButtonDown(0)) { AudioManager.instance.Play("Slicing"); weapon.Attack(); } else if (equipped && !isSword && Input.GetMouseButton(0)) { weapon.Attack(); } // animate to the pickup position if (equipped) { weapon.transform.localPosition = Vector3.Lerp(weapon.transform.localPosition, Vector3.zero, pickUpTime * Time.deltaTime); weapon.transform.localRotation = Quaternion.Lerp(weapon.transform.localRotation, Quaternion.Euler(Vector3.zero), pickUpTime * Time.deltaTime); } }
protected override void Update() { if (Input.GetKeyDown(KeyCode.F3)) { _HurtBox.GetComponent <BoxCollider2D>().enabled = !_HurtBox.GetComponent <BoxCollider2D>().enabled; } base.Update(); if (_State == CharacterBase.eState.Idle || _State == CharacterBase.eState.Move) { if (Input.GetKey(KeyCode.A)) { if (_MoveRoutine == null) { _State = CharacterBase.eState.Move; MoveOrder(Vector2.left, () => Input.GetKeyUp(KeyCode.A)); } } else if (Input.GetKey(KeyCode.D)) { if (_MoveRoutine == null) { _State = CharacterBase.eState.Move; MoveOrder(Vector2.right, () => Input.GetKeyUp(KeyCode.D)); } } if (Input.GetKeyDown(KeyCode.Space) && _CanJump) { _Rigidbody.AddForce(Vector2.up * _JumpForce, ForceMode2D.Impulse); _CanJump = false; } SetNatualAnimation(); } if ((_State == CharacterBase.eState.Idle || _State == CharacterBase.eState.Move) || _CurWeapon.isCancelable) { if (Input.GetKeyDown(KeyCode.Alpha1)) { SwapWeapon(0); } else if (Input.GetKeyDown(KeyCode.Alpha2)) { SwapWeapon(1); } else if (Input.GetKeyDown(KeyCode.Alpha3)) { SwapWeapon(2); } else if (Input.GetKeyDown(KeyCode.Alpha4)) { SwapWeapon(3); } else if (Input.GetKeyDown(KeyCode.Alpha5)) { SwapWeapon(4); } WeaponBase.eCommands Direction = WeaponBase.eCommands.None; if (Input.GetKey(KeyCode.A)) { if (Mathf.Sign(transform.localScale.x) == -1) { Direction = WeaponBase.eCommands.Front; } else { Direction = WeaponBase.eCommands.Back; } } else if (Input.GetKey(KeyCode.D)) { if (Mathf.Sign(transform.localScale.x) == 1) { Direction = WeaponBase.eCommands.Front; } else { Direction = WeaponBase.eCommands.Back; } } else if (Input.GetKey(KeyCode.W)) { Direction = WeaponBase.eCommands.Up; } else if (Input.GetKey(KeyCode.S)) { Direction = WeaponBase.eCommands.Down; } if (Input.GetKey(KeyCode.Mouse0)) { _CurWeapon.Attack(Direction, WeaponBase.eCommands.Left); } else if (Input.GetKey(KeyCode.Mouse1)) { _CurWeapon.Attack(Direction, WeaponBase.eCommands.Right); } else if (Input.GetKey(KeyCode.Mouse2)) { _CurWeapon.Attack(Direction, WeaponBase.eCommands.Middle); } } }