using UnityEngine;
using System.Collections;

public class ScreenShake : MonoBehaviour 
{
    private Vector3 currentForce;
    private float shakeTime;

    public void ShakeScreen(Vector3 forceAmount)
    {
        currentForce += forceAmount;
    }

    public void ShakeScreenRandom(float forceAmount)
    {
        int randNum = UnityEngine.Random.Range(0, 100);

        if (randNum > 75)
        {
            currentForce += new Vector3(forceAmount, 0, 0);
        }
        else if (randNum > 50)
        {
            currentForce += new Vector3(-forceAmount, 0);
        }
        else if (randNum > 25)
        {
            currentForce += new Vector3(0, forceAmount, 0);
        }
        else if (randNum > 0)
        {
            currentForce += new Vector3(0, -forceAmount, 0);
        }
    }
	
	void Update () 
    {
        transform.localPosition = Vector3.Lerp(transform.localPosition, currentForce, shakeTime);

        if (shakeTime <= 0.2f)
        {
            shakeTime += Time.deltaTime;
        }
        else
        {
            shakeTime -= Time.deltaTime;
            currentForce = Vector3.zero;
        }

        shakeTime = Mathf.Clamp(shakeTime, 0, 1);
	}
}
