From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- GenericInputHandler.cs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 GenericInputHandler.cs (limited to 'GenericInputHandler.cs') diff --git a/GenericInputHandler.cs b/GenericInputHandler.cs new file mode 100644 index 0000000..deeed7e --- /dev/null +++ b/GenericInputHandler.cs @@ -0,0 +1,40 @@ +using UnityEngine; + +public class GenericInputHandler : MonoBehaviour +{ + public Vector3 inputDirection; + + public bool normalized; + + public bool space; + + private void Start() + { + } + + private void Update() + { + space = Input.GetKey(KeyCode.Space); + inputDirection = Vector3.zero; + if (Input.GetKey(KeyCode.W)) + { + inputDirection += Vector3.forward; + } + if (Input.GetKey(KeyCode.S)) + { + inputDirection += Vector3.back; + } + if (Input.GetKey(KeyCode.D)) + { + inputDirection += Vector3.right; + } + if (Input.GetKey(KeyCode.A)) + { + inputDirection += Vector3.left; + } + if (normalized) + { + inputDirection = inputDirection.normalized; + } + } +} -- cgit v1.1-26-g67d0