31 lines
789 B
C#
31 lines
789 B
C#
using UnityEngine;
|
|
|
|
public class CameraShake : MonoBehaviour
|
|
{
|
|
private Transform camTransform;
|
|
private float shakeDuration = 1f, shakeAmount = 0.04f, decreaseFactor = 1.5f;
|
|
private Vector3 originPosition;
|
|
|
|
private void Start()
|
|
{
|
|
camTransform = GetComponent<Transform>();
|
|
originPosition = camTransform.localPosition;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if(shakeDuration > 0)
|
|
{
|
|
//Ñëó÷àéíîå çíà÷åíèå âíóòðè ñôåðû ñ ðàäèóñîì 1
|
|
camTransform.localPosition = originPosition + Random.insideUnitSphere * shakeAmount;
|
|
shakeDuration -= Time.deltaTime * decreaseFactor;
|
|
}
|
|
else
|
|
{
|
|
shakeDuration = 0;
|
|
camTransform.localPosition = originPosition;
|
|
}
|
|
}
|
|
|
|
}
|