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

public class CameraMovement : MonoBehaviour {

    public GameObject player;

    [Header("Movement Shifting")]
    [SerializeField] float xOffset;
    [SerializeField] float yOffset;
    [SerializeField] float smoothing;

    [Header("Positioning")]
    [SerializeField] float size;

    [Header("Locking")]
    [SerializeField] bool xLocked;
    [SerializeField] bool yLocked;


    void Awake() {
        FindPlayer();
        this.gameObject.GetComponent<Camera>().orthographicSize = size;
    }

    // Update is called once per frame
    void Update()
    {
        if (player != null) {
            float xPos = transform.position.x;
            float yPos = transform.position.y;

            if (!xLocked) {
                xPos = Mathf.Lerp(transform.position.x, player.transform.position.x + xOffset, Time.deltaTime * smoothing);
            }
            if (!yLocked) {
                yPos = Mathf.Lerp(transform.position.y, player.transform.position.y + yOffset, Time.deltaTime * smoothing);
            }


            this.gameObject.transform.position = new Vector3 (xPos, yPos, transform.position.z);
        }
    }

    public void FindPlayer() {
        player = GameObject.FindGameObjectWithTag("Player");
        // if (player == null) {
        //     print("null player!");
        // }
    }
}
