publicstatic KeyboardInput Instance { get { if (_instance) return _instance; _instance = FindObjectOfType<KeyboardInput>(); if (_instance) return _instance; var go = new GameObject("KeyboardInput"); _instance = go.AddComponent<KeyboardInput>();
privatevoidUpdate() { if (UnityEngine.Input.GetKey(KeyCode.A)) { Direction = new Vector2(-1, Direction.y); }
if (UnityEngine.Input.GetKey(KeyCode.D)) { Direction = new Vector2(1, Direction.y); }
if (UnityEngine.Input.GetKey(KeyCode.W)) { Direction = new Vector2(Direction.x, 1); }
if (UnityEngine.Input.GetKey(KeyCode.S)) { Direction = new Vector2(Direction.x, -1); }
if (UnityEngine.Input.GetKey(KeyCode.A) && UnityEngine.Input.GetKey(KeyCode.D)) { Direction = new Vector2(0, Direction.y); }
if (!UnityEngine.Input.GetKey(KeyCode.A) && !UnityEngine.Input.GetKey(KeyCode.D)) { Direction = new Vector2(0, Direction.y); } if (UnityEngine.Input.GetKey(KeyCode.W) && UnityEngine.Input.GetKey(KeyCode.S)) { Direction = new Vector2(Direction.x, 0); } if (!UnityEngine.Input.GetKey(KeyCode.W) && !UnityEngine.Input.GetKey(KeyCode.S)) { Direction = new Vector2(Direction.x, 0); } } } }