aboutsummaryrefslogtreecommitdiff
path: root/Assets/Scripts/InputHandler.cs
diff options
context:
space:
mode:
authorSmallFox <2806143047@qq.com>2026-05-14 21:17:29 +0800
committerSmallFox <2806143047@qq.com>2026-05-14 21:17:29 +0800
commit41def44651b5a7c9e917395fad5e7b480640a3a2 (patch)
treefe99b653b956a1be62392ddb2a5eae31f34e09a9 /Assets/Scripts/InputHandler.cs
parent738e4b973666742b077c285272d9eb50072d49dd (diff)
Movement完工
写完了移动,准备开工相机视角
Diffstat (limited to 'Assets/Scripts/InputHandler.cs')
-rw-r--r--Assets/Scripts/InputHandler.cs54
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;
+ }
+ }
+}
+