1

I'm trying to make countdown timer for adding my game match by using custom properties. But i'm stuck somewhere. Timer is working but it's not shows same time with another clients who join later. My script here:

public float Totaltime = 600;

void Update()
{
  Totaltime -= Time.deltaTime;
  StartCountDownTimer(Totaltime);
}

void StartCountDownTimer(float totalSeconds)
{
  Hashtable ht = new Hashtable() { { "startTime", totalSeconds } };
  PhotonNetwork.room.SetCustomProperties(ht);

  float updatedSecond = (float)PhotonNetwork.room.CustomProperties["startTime"];

  int minutes = Mathf.FloorToInt(updatedSecond / 60f);
  int seconds = Mathf.RoundToInt(updatedSecond % 60f);

  string formatedSeconds = seconds.ToString();

  if (seconds == 60)
  {
    seconds = 0;
    minutes += 1;
  }
}
4

1 回答 1

3

代码逻辑有问题。您应该只在主客户端上设置开始时间。其他客户端在本地客户端读取开始时间并计算剩余时间。倒计时结束后,主客户端发送 RPC 调用通知其他客户端进行下一步。

于 2019-07-22T09:40:19.770 回答