diff options
Diffstat (limited to 'InputHandler.cs')
-rw-r--r-- | InputHandler.cs | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/InputHandler.cs b/InputHandler.cs new file mode 100644 index 0000000..27adc82 --- /dev/null +++ b/InputHandler.cs @@ -0,0 +1,120 @@ +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<PlayerDeath>(); + movement = GetComponent<MovementHandler>(); + wepaonHandler = GetComponent<WeaponHandler>(); + hasControl = GetComponent<HasControl>(); + movementData = GetComponent<MovementDataHandler>(); + weaponHandler = GetComponent<WeaponHandler>(); + cameraMovement = GetComponentInChildren<CameraMovement>(); + } + + 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; + } + } +} |