using UnityEngine; public class InputHandler : MonoBehaviour { public Vector3 inputMovementDirection; public Vector3 lastInputDirection; public bool isSpringting; private WeaponHandler wepaonHandler; private MovementDataHandler movementData; private WeaponHandler weaponHandler; private CameraMovement cameraMovement; private PlayerDeath death; private HasControl hasControl; private MovementHandler movement; public bool allowStrafe = true; private void Start() { death = GetComponent(); movement = GetComponent(); wepaonHandler = GetComponent(); hasControl = GetComponent(); movementData = GetComponent(); weaponHandler = GetComponent(); cameraMovement = GetComponentInChildren(); } private void Update() { if ((bool)death && death.dead) { return; } if (!hasControl || hasControl.hasControl) { isSpringting = false; inputMovementDirection = Vector3.zero; if (Input.GetKey(KeyCode.W)) { inputMovementDirection += movementData.groundedForward; } if (Input.GetKey(KeyCode.S)) { inputMovementDirection += movementData.groundedBack; } if (Input.GetKey(KeyCode.D) && allowStrafe) { inputMovementDirection += movementData.right; } if (Input.GetKey(KeyCode.A) && allowStrafe) { inputMovementDirection += movementData.left; } if (Input.GetKey(KeyCode.LeftShift) && (!cameraMovement || !cameraMovement.ADS)) { isSpringting = true; } inputMovementDirection = inputMovementDirection.normalized; if ((bool)movement && Input.GetKeyDown(KeyCode.Space)) { movement.Jump(); } if ((bool)weaponHandler) { if (weaponHandler.isDualWeilding) { if (Input.GetKey(KeyCode.Mouse1)) { weaponHandler.HoldAttack(shootWithRightGun: true, ADS: false); } if (Input.GetKeyDown(KeyCode.Mouse1)) { weaponHandler.PressAttack(shootWithRightGun: true, ADS: false); } if (Input.GetKey(KeyCode.Mouse0)) { weaponHandler.HoldAttack(shootWithRightGun: false, ADS: false); } if (Input.GetKeyDown(KeyCode.Mouse0)) { weaponHandler.PressAttack(shootWithRightGun: false, ADS: false); } } else { if (Input.GetKey(KeyCode.Mouse1)) { cameraMovement.ADS = true; } else { cameraMovement.ADS = false; } if (Input.GetKey(KeyCode.Mouse0)) { weaponHandler.HoldAttack(shootWithRightGun: true, cameraMovement.ADS); } if (Input.GetKeyDown(KeyCode.Mouse0)) { weaponHandler.PressAttack(shootWithRightGun: true, cameraMovement.ADS); } } } } if (inputMovementDirection != Vector3.zero) { lastInputDirection = inputMovementDirection; } } }