OnServerSceneChanged is not being called and with this I can’t instantiate the GameOverHandler to manage the game over of the game. I don’t know why this is not working, please help me guys thanks a lot.
This is the code of my NetworkManager.
public class GameNetworkManager : NetworkManager
{
[SerializeField] private GameObject unitSpawnerPrefab;
[SerializeField] private GameOverHandler gameOverHandlerPrefab;
public override void OnServerAddPlayer(NetworkConnection conn)
{
base.OnServerAddPlayer(conn);
var spawnerInstance = Instantiate(
unitSpawnerPrefab,
conn.identity.transform.position,
conn.identity.transform.rotation
);
NetworkServer.Spawn(spawnerInstance, conn);
}
public override void ServerChangeScene(string newSceneName)
{
Debug.Log(SceneManager.GetActiveScene().name);
}
public override void OnServerSceneChanged(string sceneName)
{
Debug.Log(SceneManager.GetActiveScene().name);
if(SceneManager.GetActiveScene().name.StartsWith("Demo"))
{
var gameOverHandlerInstance = Instantiate(gameOverHandlerPrefab);
NetworkServer.Spawn(gameOverHandlerInstance.gameObject);
}
}
}