using UnityEngine;
using System.Collections;

public class CameraControl : MonoBehaviour {

	public GameObject player;

	public float shakeTimer;
	public float shakeAmount;

	void Update ()
	{
		transform.position = Vector3.Lerp(transform.position,
			new Vector3 (player.transform.position.x + 5, 0f ,player.transform.position.z - 5), .4f);

		if(shakeTimer >= 0) {
			Vector2 shakePos = Random.insideUnitCircle * shakeAmount;

			transform.position = new Vector3(
				transform.position.x + shakePos.x,
				transform.position.y + shakePos.y,
				transform.position.z);
			shakeTimer -= Time.deltaTime;
		}
	}

	public void shakeCamera(float shakePwr, float shakeDur)
	{
		shakeAmount = shakePwr;
		shakeTimer = shakeDur;
	}
}
