如何在 unity 5.多人游戏开始前制作计时器?

How to make timer before multiplayer game start in unity 5.?

我在这里尝试创建一个多人游戏。我想在游戏开始前放置计时器,所以我进行了研究,但无法为此找到任何解决方案。我目前正在使用 "Coroutine" 为此。但不是 working.it 为所有玩家显示不同的时间。

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);
    }
}

如果有人有此代码或教程,请分享 link。

如果我没理解错的话,你有一个等待计时器,它会一直滴答作响 10 秒。一旦为零,开始游戏计时器开始计时,只有连接的人才能玩游戏。

要使所有玩家和计时器保持同步,您必须指定一个客户端作为服务器负责使所有其他客户端保持同步,或者让服务器向连接到房间的所有玩家广播时间。否则,您将无法保持时间同步,因为玩家不会同时加入房间。