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

public class EnemyBehaviour : MonoBehaviour
{
    [SerializeField, HideInInspector] protected UnitController _unit;
    public UnitController unit
    {
        get
        {
            if (!_unit) _unit = GetComponent<UnitController>();
            return _unit;
        }
    }

    [SerializeField, HideInInspector] protected Transform _follow;
    public Transform follow
    {
        get
        {
            if (!_follow) _follow = new GameObject(name + " - Follow").transform;
            return _follow;
        }
    }
    public void DestroyFollowTarget() { if (_follow) Destroy(_follow.gameObject); }

    [SerializeField, HideInInspector] protected Transform _look;
    public Transform look
    {
        get
        {
            if (!_look) _look = new GameObject(name + " - Look").transform;
            return _look;
        }
    }
    public void DestroyLookTarget() { if (_look) Destroy(_look.gameObject); }

    public bool isPlayerControlled { get => unit && PlayerManager.I.unit == unit; }

    protected virtual void OnDestroy()
    {
        if (_follow) Destroy(_follow.gameObject);
        if (_look) Destroy(_look.gameObject);
    }
}
