Added a OnTriggerExit2D to stop attack when entity not detected
This commit is contained in:
parent
b46d8b66e8
commit
23ecdd6ab4
@ -24,7 +24,7 @@ public class Detection : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Looped detection every 'delay' amount
|
// Looped detection every 'delay' amount
|
||||||
private IEnumerator C_DetectCoroutine()
|
private IEnumerator C_DetectCoroutine()
|
||||||
{
|
{
|
||||||
// Can happen if unit dies
|
// Can happen if unit dies
|
||||||
if (_entityLinked == null) yield break;
|
if (_entityLinked == null) yield break;
|
||||||
@ -66,12 +66,12 @@ public class Detection : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTriggerStay2D(Collider2D other)
|
private void OnTriggerStay2D(Collider2D other)
|
||||||
{
|
{
|
||||||
if(_entityLinked != null && _projectileDamage == 0)
|
if (_entityLinked != null && _projectileDamage == 0)
|
||||||
{
|
{
|
||||||
GameObject detected = other.gameObject;
|
GameObject detected = other.gameObject;
|
||||||
string tagToCheck =
|
string tagToCheck =
|
||||||
(_entityLinked.gameObject.tag == "Ally") ? "Opponent" : "Ally";
|
(_entityLinked.gameObject.tag == "Ally") ? "Opponent" : "Ally";
|
||||||
|
|
||||||
if (detected.tag == tagToCheck)
|
if (detected.tag == tagToCheck)
|
||||||
@ -82,7 +82,25 @@ public class Detection : MonoBehaviour
|
|||||||
detectedEntities.Add(entity);
|
detectedEntities.Add(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user