Example #1
0
    private void OnTriggerExit2D(Collider2D other)
    {
        if (tagsToDetect.Count > 0 && !tagsToDetect.Contains(other.tag))
        {
            return;
        }

        if (!_detected.Contains(other.gameObject))
        {
            return;
        }

        _detected.Remove(other.gameObject);

        onOutOfSight?.Invoke(other.gameObject);
    }
Example #2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (tagsToDetect.Count > 0 && !tagsToDetect.Contains(other.tag))
        {
            return;
        }

        if (_detected.Contains(other.gameObject))
        {
            return;
        }

        _detected.Add(other.gameObject);

        onDetect?.Invoke(other.gameObject);
    }