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

public class LookAtTransformConstrained : MonoBehaviour
{

    public bool LockX;
    public bool LockY;
    public bool LockZ;

    public GameObject ObjectToLookat;
    public float panAmount;
    public float panSpeed;


    Camera camera;
    Vector3 startPos;



    // Start is called before the first frame update
    void Start()
    {
        camera = GetComponent<Camera>();
        startPos = this.transform.position;
        
    }

    // Update is called once per frame
    void Update()
    {
        var panVal = (panAmount * panSpeed);

        if (ObjectToLookat == null) return;
        camera.transform.position = new Vector3(
            LockX ? this.transform.position.x :
            (ObjectToLookat.transform.position.x + startPos.x) * panVal,
            LockY ? this.transform.position.y :
            (ObjectToLookat.transform.position.y + startPos.y) * panVal, 
            LockZ ? this.transform.position.z :
            (ObjectToLookat.transform.position.z + startPos.z) * panVal
            ) ;

            
    }
}
