using DG.Tweening;
Camera.main.transform.DOShakePosition(0.3f);
// 赢了抖屏幕
void Win()
{
StartCoroutine(OnShockScreen());
}
public IEnumerator OnShockScreen()
{
StartCoroutine(ShockScreen());
yield return new WaitForSeconds(0.4f);
StopCoroutine(ShockScreen());
StartCoroutine(ShockScreen());
}
public IEnumerator ShockScreen()
{
if (transform == null)
yield break;
float shakeDelta = 0.03f;
float shakeDisDelta = 0.4f;
float shakeTime = 0.2f;
while (shakeTime > 0)
{
shakeTime -= Time.deltaTime;
if (shakeTime <= 0)
{
transform.localPosition = Vector3.zero;
}
else
{
shakeDelta -= Time.deltaTime;
if (shakeDelta <= 0)
{
shakeDelta = 0.03f;
transform.localPosition = new Vector3(shakeDisDelta * (-10f + 30f * Random.value), shakeDisDelta * (-10f + 30f * Random.value), 0);
}
}
yield return 0;
}
transform.localPosition = Vector3.zero;
}