using UnityEngine;
using System.Collections;

public class cameraShakeScript : MonoBehaviour {

	public Camera mainCamera;
	private Vector3 originalCamPos;

	public float shake = 0.0f;
	public float shakeAmount = 1.0f;
	public float decreaseFactor = 1.0f;



	void Start(){

		originalCamPos = gameObject.transform.position;

	}

	void Update() {

		if(Input.GetButtonDown("Fire2")){

			shake += 0.1f;

		}

		if (shake > 0) {

			mainCamera.transform.localPosition = new Vector3(Random.value * shakeAmount, Random.value * shakeAmount, -10);
			shake -= Time.deltaTime * decreaseFactor;
			
		} else {

			shake = 0.0f;
			mainCamera.transform.localPosition = originalCamPos;

		}

	}

}
