using UnityEngine;
using Unity.Cinemachine;

public class CameraFollowPlayer : MonoBehaviour
{
    [SerializeField] private Vector3 offset = new Vector3(0, 8f, -5f);
    [SerializeField] private float damping = 1f;

    private CinemachineCamera _vcam;

    private void Start()
    {
        _vcam = GetComponent<CinemachineCamera>();
        if (_vcam == null) return;

        var local = FindFirstObjectByType<LocalPlayerController>();
        if (local != null)
            SetTarget(local.transform);
    }

    private void Update()
    {
        if (_vcam != null && _vcam.Follow == null)
        {
            var local = FindFirstObjectByType<LocalPlayerController>();
            if (local != null)
                SetTarget(local.transform);
        }
    }

    public void SetTarget(Transform target)
    {
        if (_vcam == null) return;
        _vcam.Follow = target;
    }
}
