在我的游戏中,我使用覆盖的 ServerChangeScene() 将场景更改为游戏场景。这是在 NetworkManagerLobby.cs 中完成的 NetworkManagerLobby.cs:
public void StartTransitionScene() //sets scene to loading scene
{
if (SceneManager.GetActiveScene().path == menuScene)
{
if (!IsReadyToStart()) { return; }
ServerChangeScene("Game");
}
}
public override void ServerChangeScene(string newSceneName)
{
if (SceneManager.GetActiveScene().path == menuScene && newSceneName.Contains("Game"))
{
for (int i = RoomPlayers.Count - 1; i >= 0; i--) //converts room players to game players
{
var conn = RoomPlayers[i].connectionToClient;
var gameplayerInstance = Instantiate(gamePlayerPrefab);
gameplayerInstance.SetDisplayName(RoomPlayers[i].DisplayName);
NetworkServer.Destroy(conn.identity.gameObject);
NetworkServer.ReplacePlayerForConnection(conn, gameplayerInstance.gameObject);
}
}
base.ServerChangeScene(newSceneName);
}
public override void OnServerSceneChanged(string sceneName)
{
if(sceneName.Contains("Game"))
{
GameObject playerSpawnSystemInstance = Instantiate(playerSpawnSystem);
NetworkServer.Spawn(playerSpawnSystemInstance);
}
}
场景然后转换到游戏场景(NetworkManager 没有被销毁并且存在于场景中),但是 OnServerSceneChanged 回调没有被调用。这就是为什么玩家没有在场景中的重生点上重生的原因。 现场照片
我将问题与此函数隔离,因为我认为问题在于生成系统本身。调试时未调用该函数。
这个问题你找到解决办法了吗?