using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class BasicUnitController : UnitController
{
    protected NavMeshAgent _nav;

    [SerializeField] private Transform target;
    [SerializeField] private Transform focus;

    public override Transform lookTarget { get => focus; set => focus = value; }
    public override Transform moveTarget { get => target; set => target = value; }
    // private bool isPlayerAlive = true;

    // void Awake() {
    //     PlayerManager.I.playerDeath += OnPlayerDeath;
    // }
    // void OnDestroy() {
    //     PlayerManager.I.playerDeath -= OnPlayerDeath;
    // }
    // private void OnPlayerDeath() {
    //     isPlayerAlive = false;
    // }

    protected virtual void Start()
    {
        _nav = GetComponent<NavMeshAgent>();
    }
    protected virtual void Update()
    {
        if(/*isPlayerAlive &&*/ PlayerManager.I.unit != null) {
            if (moveTarget)
                _nav.SetDestination(moveTarget.position);
            if (focus)
            {
                transform.LookAt(focus);
                var rot = transform.rotation.eulerAngles;
                rot.x = 0;
                rot.z = 0;
                transform.rotation = Quaternion.Euler(rot);
            }
        }
    }

    public override void Attack()
    {
        // Debug.Log("Unit (" + name + ") attacked");
    }
}
