[英]How to make timer before multiplayer game start in unity 5.?
在这里,我试图创建一个多人游戏。 我想在游戏开始前设置计时器,所以我进行了研究,但对此没有任何解决方案。 我目前正在为此使用“协程”。 但无法正常工作。它为所有玩家显示了不同的时间。
private int j = 10;
void Start()
{
if (isLocalPlayer)
StartCoroutine (GameStartTimer ());
}
IEnumerator GameStartTimer()
{
while (j > 0) {
j = j - 1;
Debug.Log ("Value of j is : " + j);
startTimertext.text = j.ToString ();
yield return new WaitForSeconds (1);
}
//ObjectParentingSystem ();
GetPlayerAnimandRGB ();
StartCoroutine (StartPlayerTimer ());
//yield return new WaitForSeconds (10);
gameStartTextPanel.SetActive (false);
}
我也尝试下面的代码,但不能成功。
void Start()
{
if (isServer){
StartCoroutine (GameStartTimer ());
}
else{
GetPlayerAnimandRGB ();
StartCoroutine (StartPlayerTimer ());
//yield return new WaitForSeconds (10);
gameStartTextPanel.SetActive (false);
}
}
如果任何人有此代码或教程的代码,则请共享链接。
如果我理解这一权利,则您有一个等待计时器,该计时器持续滴答10秒钟。 一旦为零,则开始游戏计时器开始计时,只有连接的那些人才能玩游戏。
为了使所有玩家和计时器保持同步,您必须指定一个客户端作为负责使所有其他客户端保持同步的服务器,或者让服务器向连接到该房间的所有玩家广播时间。 否则,您将无法保持时间同步,因为玩家不会同时加入游戏室。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.