using UnityEngine;
using System.Collections;

public class CameraFollowScript : MonoBehaviour {

    [SerializeField]
    private float dampTime = 0.15f;
    [SerializeField]
    private float _verticalOffset;
    private Vector3 velocity = Vector3.zero;

    private Transform target;

    void Awake() {
        this.target = GameObject.FindGameObjectWithTag("RaidBoss").transform;
    }

    // Update is called once per frame
    void Update() {
        if (target) {
            Vector3 point = Camera.main.WorldToViewportPoint(target.position);
            Vector3 delta = target.position - Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, point.z));
            Vector3 destination = transform.position + delta;
            destination.y += this._verticalOffset;
            transform.position = Vector3.SmoothDamp(transform.position, destination, ref velocity, dampTime);
        }

    }

    public static void AssignNewTarget(GameObject gameObj) {
        CameraFollowScript camScript = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraFollowScript>();
        camScript.target = gameObj.transform;
    }
}