using Unity.Mathematics; using UnityEngine; public class Pacman : MonoBehaviour { public Movement movement { get; private set;} private void Awake() { this.movement = GetComponent(); } private void Update() { if(Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { this.movement.SetDirection(Vector2.up); } else if(Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { this.movement.SetDirection(Vector2.down); } else if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { this.movement.SetDirection(Vector2.left); } else if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { this.movement.SetDirection(Vector2.right); } float angle = Mathf.Atan2(this.movement.direction.y ,this.movement.direction.x); this.transform.rotation = Quaternion.AngleAxis(angle * Mathf.Rad2Deg, Vector3.forward); } public void ResetState() { this.movement.ResetState(); this.gameObject.SetActive(true); } }