[英]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.