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

public class ScreenShake : MonoBehaviour
{
   

    // Update is called once per frame
    void Update()
    {
        
    }

    public void Shake(float _str, float _time)
    {
        StartCoroutine(ShakeCoro(_str, _time));
    }

    IEnumerator ShakeCoro(float _str, float _time)
    {
        Vector3 startPos = transform.position;
        float t = 0; 

        while(t < 1)
        {
            t = Mathf.MoveTowards(t, 1, Time.deltaTime / _time);
            Vector3 offset = new(Random.Range(-_str, _str), Random.Range(-_str, _str));

            transform.position = startPos + offset;

            yield return null;
        }

        transform.position = startPos;
    }
}
