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

public class Screenshake : MonoBehaviour {

    // How long the object should shake for.
    public float ShakeDuration = 0f;

    // Amplitude of the shake. A larger value shakes the camera harder.
    public float ShakeAmount = 0.7f;
    public float DecreaseFactor = 1.0f;

    private Vector3 OriginalPos;
    // Use this for initialization
    void Start ()
    {
        OriginalPos = Camera.main.transform.localPosition;
        ShakeDuration = 3.0f;
    }

    void Update()
    {
        if (ShakeDuration > 0)
        {
            Camera.main.transform.localPosition = OriginalPos + Random.insideUnitSphere * ShakeAmount;

            ShakeDuration -= Time.deltaTime * DecreaseFactor;
        }
        else
        {
            ShakeDuration = 0f;
            Camera.main.transform.localPosition = OriginalPos;
        }
    }
}
