using UnityEngine;
using System.Collections;

public class CameraFollow : MonoBehaviour {
    public Transform target;
    public float delay = 3;
    public float maxLeft;
    public float maxRight;
    public float maxTop;
    public float maxBottom;

    Vector3 deltaMove;
	void Start () {
        Screen.SetResolution(1280, 720, true);
        deltaMove = Vector3.zero;
	}
	
	// Update is called once per frame
	void Update () {
        if (transform.position != target.transform.position)
        {
            deltaMove = target.transform.position - transform.position;
            deltaMove.z = 0;
            transform.Translate(deltaMove / delay);
            if (transform.position.x < maxLeft)
            {
                deltaMove = Vector3.zero;
                deltaMove.x = maxLeft - transform.position.x;
                transform.Translate(deltaMove);
            }
            else if (transform.position.x > maxRight)
            {
                deltaMove = Vector3.zero;
                deltaMove.x = maxRight - transform.position.x;
                transform.Translate(deltaMove);
            }
            if (transform.position.y > maxTop)
            {
                deltaMove = Vector3.zero;
                deltaMove.y = maxTop - transform.position.y;
                transform.Translate(deltaMove);
            }
            else if (transform.position.y < maxBottom)
            {
                deltaMove = Vector3.zero;
                deltaMove.y = maxBottom - transform.position.y;
                transform.Translate(deltaMove);
            }
        }
	}
}
