Added a OnTriggerExit2D to stop attack when entity not detected

This commit is contained in:
Adam Salah 2025-05-28 19:16:04 -04:00
parent b46d8b66e8
commit 23ecdd6ab4

View File

@ -85,6 +85,24 @@ public class Detection : MonoBehaviour
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (_entityLinked != null)
{
GameObject detected = other.gameObject;
string tagToCheck =
(_entityLinked.gameObject.tag == "Ally") ? "Opponent" : "Ally";
if (detected.tag == tagToCheck)
{
Entity entity = other.GetComponent<Entity>();
if (detectedEntities.Contains(entity))
{
detectedEntities.Remove(entity);
}
}
}
}
public Entity GetClosest()
{
Entity closest = null;