- Home /
Multiplayer client and server aren't talking to each other properly after changing scenes
So my game starts out with a character selection/stage selection scene. Everything seems to work fine there, but once I actually load up the stage the problem begins.
So the level loads correctly on both systems, and the selected characters instantiate properly, but after that, they disagree with each other. The server can move his own character on his own screen just fine, but he doesn't move at all on the client's screen.
The client meanwhile, can't move his own character on either screen, but that's a secondary concern, since I think once I fix the first problem the second problem will fall into place.
Here's the relevant code as far as I can tell: Starting the server:
function StartServer()
{
Network.InitializeServer(numPlayers+1, listenPort, !Network.HavePublicAddress());
MasterServer.RegisterHost(typeName, gameName);
var ply: PlayerInfo = GameObject.FindObjectOfType(PlayerInfo);
var go : GameObject = empty;
players[Network.player] = go;
}
client joins the server:
function OnPlayerConnected(player: NetworkPlayer)
{
var ply: PlayerInfo = GameObject.FindObjectOfType(PlayerInfo);
var go : GameObject = empty;
players[player] = go;
networkView.RPC("updatePlayers", RPCMode.All, player);
}
Instantiating the objects (Server):
function spawnCharacters()
{
for (var j in players.Keys)
{
player1 = Network.Instantiate(players[j], Vector3.up*3, Quaternion.identity, 0);
playersField[j] = player1;
}
}
loading the level looks like this:
function stageSelect()
{
if (GUILayout.Button("Tutorial"))
{
networkView.RPC("LoadLevel", RPCMode.All, "Tutorial");
}
}
@RPC
function LoadLevel (level : String)
{
Application.LoadLevel(level);
}
for simplicity, right now the command is this
if (Input.GetButton(RIGHT))
playersField[Network.player].transform.Translate(Vector2(1,0));
When I load up a server and a client, the character will move in the server's window but not the client's.