Added a OnTriggerExit2D to stop attack when entity not detected
This commit is contained in:
parent
b46d8b66e8
commit
23ecdd6ab4
@ -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()
|
public Entity GetClosest()
|
||||||
{
|
{
|
||||||
Entity closest = null;
|
Entity closest = null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user