Files
PrinceOfGlory/Assets/Scripts/Help/CameraShake.cs
kridoo 6e91a0c7f0 111
2025-09-15 17:32:08 +08:00

48 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BigSpace.Logic;
using BigSpace.XRCore.Event;
using UnityEngine.Playables;
using BigSpace.XRCore.Base;
public class CameraShake : MonoSingleton<CameraShake>
{
bool isShake = false;
//¼ÆÊ±Ïà¹Ø
float waitTime = 10f;
float runTime = 0;
Vector3 StarPositon;
// Start is called before the first frame update
void Start()
{
GlobalEventMgr.Listen(GameEvent.EventCameraShake, GameDataManage_EventCameraShake);
StarPositon = this.transform.localPosition;
}
void GameDataManage_EventCameraShake()
{
isShake = true;
}
private void Update()
{
if (isShake)
{
Vector3 shake = new Vector3(Random.Range(-0.5f, 0.5f), Random.Range(-1.0f, 1.0f), 0);
transform.localPosition += shake * Time.deltaTime;
runTime += Time.deltaTime;
if (runTime >= waitTime)
{
isShake = false;
runTime = 0;
transform.localPosition = StarPositon;
}
}
}
}