using System.Collections;
using UnityEngine;
class CameraShake : MonoBehaviour
{
private Transform ThisTransform = null;
public float ShakeTime = 2.0f;
public float ShakeAmount = 3.0f;
public float ShakeSpeed = 2.0f;
void start()
{
ThisTransform = GetComponent<Transform>();
StartCoroutine(Shake());
}
public IEnumerator Shake()
{
Vector3 OrigPos = ThisTransform.localPosition;
float ElapsedTime = 0.0f;
while (ElapsedTime < ShakeTime)
{
Vector3 RandomPoint = OrigPos + Random.insideUnitSphere * ShakeAmount;
ThisTransform.localPosition = Vector3.Lerp(ThisTransform.localPosition, RandomPoint, Time.deltaTime * ShakeSpeed);
yield return null;
ElapsedTime += Time.deltaTime;
}
ThisTransform.localPosition = OrigPos;
}
}