0

I'm trying to switch a scene over the network and i want each player to locally load the scene Async so that everyone can get a loading screen. I'm struggling with Command and RPC calls. After the scene changes i would like to respawn a new player and associate it with the client.

public void changeLevel(string name)
{
    CmdChangeLevel(name);
    //nm.ServerChangeScene(name); -> This doesnt change the scene Async
}

void changeScene(string name)
{
    SceneManager.LoadScene(name);

    //Stuff to re-Instantiate the player
}

[Command]
void CmdChangeLevel(string name)
{
    SceneManager.LoadScene(name);
    RpcChangeLevel(name);
}

[ClientRpc]
void RpcChangeLevel(string name)
{
    changeScene(name);
}

Everything i tried resulted in a scene switch but no players instantiated, like (nm = networkManager) nm.OnServerAddPlayer() and instantiate it then spawn it through the server. Help would be much appreciated, thanks in advance

Yooooomi
  • 895
  • 1
  • 8
  • 20

1 Answers1

0

Perhaps what you need is a static gamemanager with DontDestroyOnLoad (DDOL)? Basically what you do is:

1) Create a scene and put it first in your game build order (so game first load in to it)

2) Create an empty GameObject with a GameManager script. In Start() put the DontDestroyOnLoad-method.

3) In your script, load your "first" scene (main menu or splash screen or whatever)

This will make the Object you put your DDOL-script to stay even between scene changes, so you could handle the loading screens and player spawns etc in that gameobject.

Fredrik Schön
  • 4,888
  • 1
  • 21
  • 32
  • Basically what I want to know is how do I spawn manually the player prefab of the Network Manager. I need the client to load the scene locally and ask the server to respawn his player you know ? – Yooooomi Jan 13 '17 at 14:22