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

30 lines
816 B
C#

using UnityEngine;
public class Ghost_Scatter : Ghost_behaviour
{
private void OnDisable()
{
this.ghost.chase.Enable();
}
private void OnTriggerEnter2D(Collider2D other)
{
Nodes node = other .GetComponent<Nodes>();
if(node != null && this.enabled && !this.ghost.Frightened.enabled)
{
int index = Random.Range(0, node.availableDirections.Count);
if(node.availableDirections[index] == -this.ghost.movement.direction && node.availableDirections.Count > 1)
{
index++;
if(index >= node.availableDirections.Count)
{
index = 0;
}
}
this.ghost.movement.SetDirection(node.availableDirections[index]);
}
}
}