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

public class CameraController : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
		{
			CameraShake(0.2f, 0.1f);
		}
    }

	private void OnDrawGizmos()
	{
		Gizmos.DrawWireSphere(transform.position, 0.05f);
	}

	private void CameraShake(float amount, float time)
	{
		StartCoroutine(CameraShaking(amount, time));
	}

	private IEnumerator CameraShaking(float amount, float time)
	{
		Vector3 oriPos = transform.position;
		Debug.Log(oriPos);
		float oriAmount = amount;
		float oriTime = time;
		for (float t = 0; t < time; t += Time.deltaTime)
		{
			Vector3 randVec = UnityEngine.Random.insideUnitSphere;
			amount = oriAmount * ((time - t) / oriTime);
			transform.position = oriPos + randVec * amount;
			yield return new WaitForEndOfFrame();
		}
		transform.position = oriPos;
	}


}
