using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UI;

public class Enemy : MonoBehaviour
{
    public int maxLife = 100;
    public int currentLife;
    public float detectPlayer = 10f;
    public Transform player;
    public NavMeshAgent agent;
    public Animator anim;

    public virtual void Start()
    {
        currentLife = maxLife;
        player = GameObject.Find("Player").transform;
        agent = GetComponent<NavMeshAgent>();
        //anim = GetComponent<Animator>();
    }

    public virtual void Update()
    {
        if (Vector3.Distance(transform.position, player.position) <= detectPlayer)
        {
            TargetPlayer();
        }
    }

    public virtual void TargetPlayer()
    {
        // Se sobreescribe en las clases hijas
    }

    public virtual void ReceiveDamage(int received)
    {
        currentLife -= received;
        if (currentLife <= 0)
        {
            Die();
        }
    }

    protected virtual void Die()
    {
        Destroy(gameObject);
    }
}
