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

public class CameraControler : MonoBehaviour
{

	public float cameraSize;
	public float orthoSizeMin;
	public float orthoSizeMax;
	public float camSpeed;
    

	private Camera cam;
	private float camXMin = 0f;
	private float camXMax = 6f;
	private float camYMin = -3f;
	private float camYMax = 3.5f;

	// Use this for initialization
	void Start ()
	{
		cameraSize = 12;
		cam = GetComponent<Camera> ();
	}
	
	// Update is called once per frame
	void Update ()
	{
		if (Input.GetAxis ("Mouse ScrollWheel") < 0) {
			cameraSize += 0.5f;
		}
		if (Input.GetAxis ("Mouse ScrollWheel") > 0) {
			cameraSize -= 0.5f;
		}


		Vector3 newCamPos = new Vector3 (cam.transform.localPosition.x, cam.transform.localPosition.y, cam.transform.localPosition.z);
		if (Input.GetKey (KeyCode.W))
			newCamPos.y += camSpeed * Time.deltaTime;
		if (Input.GetKey (KeyCode.A))
			newCamPos.x -= camSpeed * Time.deltaTime;            
		if (Input.GetKey (KeyCode.S))
			newCamPos.y -= camSpeed * Time.deltaTime;
		if (Input.GetKey (KeyCode.D))
			newCamPos.x += camSpeed * Time.deltaTime;
		cameraSize = Mathf.Clamp (cameraSize, orthoSizeMin, orthoSizeMax);

		// update Game Cam
		cam.orthographicSize = cameraSize;
		cam.transform.localPosition = new Vector3 (Mathf.Clamp (newCamPos.x, camXMin, camXMax),
			Mathf.Clamp (newCamPos.y, camYMin, camYMax),
			newCamPos.z);
		;
	}
}
