You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
662 B
28 lines
662 B
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CameraShake : MonoBehaviour
|
|
{
|
|
|
|
public IEnumerator Shake(float duration, float magnitude)
|
|
{
|
|
Vector3 originalPos = transform.localPosition;
|
|
|
|
float elapsed = -0.15f;
|
|
|
|
while (elapsed < duration)
|
|
{
|
|
float x = Random.Range(-0.7f, 0.7f) * magnitude;
|
|
float y = Random.Range(-0.7f, 0.7f) * magnitude;
|
|
|
|
transform.localPosition = new Vector3(x, y, originalPos.z);
|
|
|
|
elapsed += Time.deltaTime;
|
|
|
|
yield return null;
|
|
}
|
|
|
|
transform.localPosition = originalPos;
|
|
}
|
|
}
|