我在多人游戏中遇到了对象实例化的问题。游戏布局很简单:玩家进入大厅,一旦每个人都标记准备就绪,倒计时和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);
}