diff options
Diffstat (limited to 'Assets/Scripts/InputHandler.cs')
| -rw-r--r-- | Assets/Scripts/InputHandler.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Assets/Scripts/InputHandler.cs b/Assets/Scripts/InputHandler.cs new file mode 100644 index 0000000..ec72656 --- /dev/null +++ b/Assets/Scripts/InputHandler.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace DS +{ + public class InputHandler : MonoBehaviour + { + public float horizontal; + public float vertical; + public float moveAmount; + public float mouseX; + public float mouseY; + + private PlayerControls _inputActions; + + private Vector2 _movementInput; + private Vector2 _cameraInput; + + public void OnEnable() + { + if (_inputActions == null) + { + _inputActions = new PlayerControls(); + _inputActions.PlayerMovement.Movement.performed += + ctx => _movementInput = ctx.ReadValue<Vector2>(); + _inputActions.PlayerMovement.Camera.performed += ctx => _cameraInput = ctx.ReadValue<Vector2>(); + } + + _inputActions.Enable(); + } + + private void OnDisable() + { + _inputActions.Disable(); + } + + public void TickInput(float delta) + { + MoveInput(delta); + } + + private void MoveInput(float delta) + { + horizontal = _movementInput.x; + vertical = _movementInput.y; + moveAmount = Mathf.Clamp01(Mathf.Abs((horizontal)) + Mathf.Abs(vertical)); + mouseX = _cameraInput.x; + mouseY = _cameraInput.y; + } + } +} + |
