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

public class CameraController : MonoBehaviour
{
    public Transform targetGameObject = null;

    public BoundsInt mapBounds;
    
    void Update()
    {
        if (targetGameObject != null) {
            Vector3 pos = targetGameObject.position;
            pos.z = transform.position.z;

            Vector3 oldPos = transform.position;

            Vector3 newPos = pos * 0.01f + oldPos * 0.99f;

            if (newPos.x < mapBounds.x) {
                newPos.x = mapBounds.x;
            }

            if (newPos.x > mapBounds.size.x) {
                newPos.x = mapBounds.size.x;
            }

            if (newPos.y < mapBounds.y) {
                newPos.y = mapBounds.y;
            }

            if (newPos.y > mapBounds.size.y) {
                newPos.y = mapBounds.size.y;
            }


            transform.position = newPos;
        }
    }
}
