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)
|
|||
|
{
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1
|
|||
|
camTransform.localPosition = originPosition + Random.insideUnitSphere * shakeAmount;
|
|||
|
shakeDuration -= Time.deltaTime * decreaseFactor;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
shakeDuration = 0;
|
|||
|
camTransform.localPosition = originPosition;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|