2023-05-12 19:29:21 -04:00

33 lines
908 B
C#

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<Entity>();
}
//Detect the enemy and inform the Entity
if (other.gameObject.tag == "Ally" && _entityLinked.GetType() == typeof(Opponent)) {
_entityLinked.IsEnemyDetected = true;
_entityLinked.Enemy = other.gameObject.GetComponent<Entity>();
}
}
void OnTriggerExit2D(Collider2D other)
{
_entityLinked.IsEnemyDetected = false;
}
}