C# 与光子统一的倒计时计时器';s双关2

C# 与光子统一的倒计时计时器';s双关2,c#,unity3d,photon,C#,Unity3d,Photon,在我的游戏中,我需要为所有玩家创建一个同步的计时器倒计时,这个计时器需要在DontDestroyOnLoad(支持场景更改)上,因为在我的游戏中有很多这样的场景更改。你知道我怎么做吗? PS:我用的是光子的PUN2,所以PUN1几乎没什么用 使用光子在多人游戏中实现计时器的最简单方法。使用计时器在UI上应用此脚本 bool startTimer = false; double timerIncrementValue; double startTime; [SerializeField] doub

在我的游戏中,我需要为所有玩家创建一个同步的计时器倒计时,这个计时器需要在DontDestroyOnLoad(支持场景更改)上,因为在我的游戏中有很多这样的场景更改。你知道我怎么做吗?
PS:我用的是光子的PUN2,所以PUN1几乎没什么用

使用光子在多人游戏中实现计时器的最简单方法。使用计时器在UI上应用此脚本

bool startTimer = false;
double timerIncrementValue;
double startTime;
[SerializeField] double timer = 20;
ExitGames.Client.Photon.Hashtable CustomeValue;

void Start()
 {
     if (PhotonNetwork.player.IsMasterClient)
     {
         CustomeValue = new ExitGames.Client.Photon.Hashtable();
         startTime = PhotonNetwork.time;
         startTimer = true;
         CustomeValue.Add("StartTime", startTime);
         PhotonNetwork.room.SetCustomProperties(CustomeValue);
     }
     else
     {
         startTime = double.Parse(PhotonNetwork.room.CustomProperties["StartTime"].ToString());
         startTimer = true;
     }
 }

void Update()
 {
     if (!startTimer) return;
     timerIncrementValue = PhotonNetwork.time - startTime;
     if (timerIncrementValue >= timer)
     {
        //Timer Completed
        //Do What Ever You What to Do Here
     }
 }