using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraShake : MonoBehaviour { public static CameraShake Ins; public float ShakeAmount; float ShakeTime; Vector3 initialPosition = new Vector3(0f, 3.1f, -2f); public void VibrateForTime(float time) { ShakeTime = time; } private void Awake() { Ins = this; } private void Start() { initialPosition = transform.localPosition; } void Update() { if (ShakeTime > 0f) { transform.localPosition = new Vector3(initialPosition.x + Random.Range(-ShakeAmount, ShakeAmount), initialPosition.y + Random.Range(-ShakeAmount, ShakeAmount), initialPosition.z); ShakeTime -= Time.deltaTime; if (ShakeTime <= 0f) transform.localPosition = initialPosition; } } }