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

62 lines
1.6 KiB
C#

using UnityEngine;
public class Ghost : MonoBehaviour
{
///public new Rigidbody2D rigidbody { get; private set;}
public Movement movement { get; private set;}
public Ghost_Home home { get; private set;}
public Ghost_Scatter scatter { get; private set;}
public Ghost_Chase chase { get; private set;}
public Ghost_Frightened Frightened { get; private set;}
public Ghost_behaviour initialBehavior;
public Transform target;
public int points = 200;
private void Awake()
{
this.movement = GetComponent<Movement>();
this.home = GetComponent<Ghost_Home>();
this.scatter = GetComponent<Ghost_Scatter>();
this.chase = GetComponent<Ghost_Chase>();
this.Frightened = GetComponent<Ghost_Frightened>();
}
public void Start()
{
ResetState();
}
public void ResetState()
{
this.gameObject.SetActive(true);
this.movement.ResetState();
this.Frightened.Disable();
this.chase.Disable();
this.scatter.Enable();
if(this.home != this.initialBehavior)
{
this.home.Disable();
}
if(this.initialBehavior != null)
{
this.initialBehavior.Enable();
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.layer == LayerMask.NameToLayer("Pacman"))
{
if(this.Frightened.enabled)
{
FindAnyObjectByType<GameManager>().GhostEaten(this);
}
else
{
FindAnyObjectByType<GameManager>().PacmanEaten();
}
}
}
}