簡體   English   中英

結合Photon的PUN 2的倒數計時器

[英]Countdown Timer in Unity with Photon's PUN 2

在我的游戲中,我需要創建一個為所有玩家同步的倒計時計時器,該計時器需要處於DontDestroyOnLoad(支持場景更改)上,因為在我的游戲中,這些場景更改很多。 你知道我該怎么做嗎? PS:我使用的是Photon的PUN2,因此,幾乎所有PUN1都不起作用。

使用光子在多人游戲上實現計時器的最簡單方法。 使用Timer在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
     }
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM