using UnityEngine;
using System.Collections;

public class Camera_Move_Sc : MonoBehaviour {

	public GameObject Player;
	public float Diff = 5;
    public Camera cam;
    public Vector3 shakeSize = new Vector3(100,100,0);


	//private Camera camera;
	private Vector3 cameraMove;
	// Use this for initialization
	void Start () {
	
	//	camera = GetComponent<Camera>();
		cameraMove = new Vector3(0,0,0);
        cam = GetComponent<Camera>();
	}
	
	// Update is called once per frame
	void Update () {

		Vector3 playerMove = Player.transform.position;


		cameraMove.z = -2;


		if (playerMove.x - GetComponent<Camera>().transform.position.x > Diff) {
			cameraMove.x = playerMove.x - Diff;
		}
		if (playerMove.x - GetComponent<Camera>().transform.position.x < Diff * -1) {
			cameraMove.x = playerMove.x + Diff;
		}
		if (playerMove.y - GetComponent<Camera>().transform.position.y > Diff) {
			cameraMove.y = playerMove.y - Diff;
		}
		if(playerMove.y - GetComponent<Camera>().transform.position.y < Diff * -1){		
			cameraMove.y = playerMove.y + Diff;
		}
        
		GetComponent<Camera>().transform.position = cameraMove;





	}

    public void CameraShake()
    {
        Debug.Log("Shaking!");
        cam.transform.localPosition = Random.insideUnitSphere + shakeSize * Time.deltaTime;
    }
}
