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

public class CameraFollow : MonoBehaviour
{
    [SerializeField] private Transform _target;
    [SerializeField] private float _smoothSpeed = 5f;

    private float _offsetY;
    private float _minY;

    void Start()
    {
        _offsetY = transform.position.y - _target.position.y;
        _minY = transform.position.y;
    }

    void LateUpdate()
    {
        float targetY = Mathf.Max(_target.position.y + _offsetY, _minY);
        Vector3 newPos = new Vector3(transform.position.x, targetY, transform.position.z);
        transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * _smoothSpeed);
    }
}
