我在多人游戏中遇到对象实例化问题。游戏布局很简单:玩家进入大厅,一旦每个人都准备好,就会出现倒计时和加载游戏关卡的LobbyManager
调用。ServerChangeScene(gameScene)
问题是在很多负载上,所有联网对象都没有在客户端上实例化。经过一些游戏测试后,我注意到这似乎只发生在client
服务器之前加载场景时 - 当server
首先加载时一切都正确显示并且游戏正常运行。有没有办法确保服务器首先加载?
一些代码供参考:
public override void OnLobbyServerPlayersReady()
{
currentNumberTeam1 = 0;
currentNumberTeam2 = 0;
StartCoroutine(ServerCountdownCoroutine());
}
public IEnumerator ServerCountdownCoroutine()
{
float remainingTime = _matchStartCountdown;
int floorTime = Mathf.FloorToInt(remainingTime);
while (remainingTime > 0)
{
yield return null;
remainingTime -= Time.deltaTime;
int newFloorTime = Mathf.FloorToInt(remainingTime);
if (newFloorTime != floorTime)
{
floorTime = newFloorTime;
for (int i = 0; i < lobbySlots.Length; ++i)
{
if (lobbySlots[i] != null)
{
(lobbySlots[i] as CharacterSelect).RpcUpdateCountdown(floorTime);
}
}
}
}
for (int i = 0; i < lobbySlots.Length; ++i)
{
if (lobbySlots[i] != null)
{
(lobbySlots[i] as CharacterSelect).RpcUpdateCountdown(0);
}
}
ServerChangeScene(playScene);
}