using System.Collections; using System.Collections.Generic; using UnityEngine; public class Detection : MonoBehaviour { [SerializeField] private Entity _entityLinked; void OnTriggerEnter2D(Collider2D other) { //Detect the enemy and inform the Entity if (other.gameObject.tag == "Opponent" && _entityLinked.GetType() == typeof(Ally)) { _entityLinked.IsEnemyDetected = true; _entityLinked.Enemy = other.gameObject.GetComponent(); } //Detect the enemy and inform the Entity if (other.gameObject.tag == "Ally" && _entityLinked.GetType() == typeof(Opponent)) { _entityLinked.IsEnemyDetected = true; _entityLinked.Enemy = other.gameObject.GetComponent(); } } void OnTriggerExit2D(Collider2D other) { _entityLinked.IsEnemyDetected = false; } }