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

public class CameraFollow : MonoBehaviour
{
    //public GameObject player;
    //public Camera main_camera;

    //private void Awake()
    //{
    //    player = GameObject.FindGameObjectWithTag("Player");
    //    main_camera = GetComponent<Camera>();
    //}

    //void Update()
    //{
    //    if (player != null)
    //    {
    //        float player_x = player.transform.position.x;
    //        float player_y = player.transform.position.y;

    //        float rounded_x = RoundToNearestPixel(player_x);
    //        float rounded_y = RoundToNearestPixel(player_y);

    //        Vector3 new_pos = new Vector3(rounded_x, rounded_y, -10.0f); // this is 2d, so my camera is that far from the screen.
    //        main_camera.transform.position = new_pos;
    //    }
    //}
    //public float pixelToUnits = 40f;

    //public float RoundToNearestPixel(float unityUnits)
    //{
    //    float valueInPixels = unityUnits * pixelToUnits;
    //    valueInPixels = Mathf.Round(valueInPixels);
    //    float roundedUnityUnits = valueInPixels * (1 / pixelToUnits);
    //    return roundedUnityUnits;
    //}

    public Transform Target;

    public float DefaultZ = -10;
    public float SmoothTime = 0.2f;

    private Vector3 _refVel = Vector3.zero;

    private void LateUpdate()
    {
        Vector3 targetPosition = new Vector3(Target.transform.position.x, Target.transform.position.y, DefaultZ);

        transform.position = Vector3.SmoothDamp(transform.position, targetPosition,
            ref _refVel, SmoothTime * Time.deltaTime);
    }
}
