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

public class PlayerFollow : MonoBehaviour
{
    [Header("Pathfinding")]
    public float distance = 3f;
    // private bool isPlayerAlive = true;

    // void Awake() {
    //     PlayerManager.I.playerDeath += OnPlayerDeath;
    // }

    // void OnDestroy() {
    //     PlayerManager.I.playerDeath -= OnPlayerDeath;
    // }

    // private void OnPlayerDeath() {
    //     isPlayerAlive = false;
    // }
    private void Update()
    {
        if(/*isPlayerAlive && */PlayerManager.I.unit != null && PlayerManager.I.follow != null) {
            var player = PlayerManager.I.unit;
            var follow = PlayerManager.I.follow;

            player.moveTarget = follow;

            var x = Input.GetAxis("Horizontal");
            var y = Input.GetAxis("Vertical");
            var delta = new Vector3(x, 0, y).normalized * distance;

            follow.position = player.transform.position + delta;
        }
    }
}
