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

public class CameraFollowBehavior : MonoBehaviour
{
    public float BoxSizeX;
    public float BoxSizeY;
    public GameObject FollowTarget;
   

    private void Update()
    {
        Vector2 cam2Target = transform.position - FollowTarget.transform.position;

        float x = 0;
        float y = 0;

        if (cam2Target.x > BoxSizeX)
        {
            x = BoxSizeX;
        }
        else if (cam2Target.x < -BoxSizeX)
        {
            x = -BoxSizeX;
        }

        if (cam2Target.y > BoxSizeY)
        {
            y = BoxSizeY;
        }
        else if (cam2Target.y < -BoxSizeY)
        {
            y = -BoxSizeY;
        }

        transform.position = Vector3.Lerp(transform.position, new Vector3(FollowTarget.transform.position.x + x, FollowTarget.transform.position.y + y, transform.position.z), Time.deltaTime*5f);
    }
}
