Pacman/Assets/Scripts/Pacman.cs
2025-04-20 21:10:16 +05:30

39 lines
1.1 KiB
C#

using Unity.Mathematics;
using UnityEngine;
public class Pacman : MonoBehaviour
{
public Movement movement { get; private set;}
private void Awake()
{
this.movement = GetComponent<Movement>();
}
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);
}
}