hey I’m trying to give my server the option to choose the level to play, which works. don’t know if it is the best way to do it before I actually start the server or if i better do it after the server is up… anyway that’s not my problem.
the client doesn’t have the map loaded if i connect to the server. i use 1 build and so off course the level isn’t loaded if i connect to the server… so my Question is what would be the best way to update my client with what is on the server once it connects?
I’m a noob programmer and tried RPC’s but it so confusing.
this how i load the level on the server and start the server:
...
if (iWantToSetupAServer !picked)
{
GUILayout.Label("Select a Level");
scrollPosition=GUILayout.BeginScrollView (scrollPosition);
foreach(string level in levels)
{
if (GUILayout.Button(level))
{
Application.LoadLevelAdditive(level);
picked=true;
levelOnServer=level;
}
}
GUILayout.EndScrollView();
}
if(iWantToSetupAServer == true picked)
{
GUILayout.Label("Enter a name for your server");
serverName = GUILayout.TextField(serverName);
GUILayout.Space(5);
GUILayout.Label("Server Port");
connectionPort = int.Parse(GUILayout.TextField(connectionPort.ToString()));
GUILayout.Space(10);
if(GUILayout.Button("Start my own server", GUILayout.Height(30)))
{
Network.InitializeServer(numberOfPlayers, connectionPort, useNAT);
PlayerPrefs.SetString("serverName", serverName);
iWantToSetupAServer = false;
}
if(GUILayout.Button("Go Back", GUILayout.Height(30)))
{
iWantToSetupAServer = false;
}
}
...
this is the code in the same script i use to connect to the server:
...
if(iWantToConnectToAServer == true)
{
GUILayout.Label("Enter your player name");
playerName = GUILayout.TextField(playerName);
GUILayout.Space(5);
GUILayout.Label("Type in Server IP");
connectToIP = GUILayout.TextField(connectToIP);
GUILayout.Space(5);
GUILayout.Label("Server Port");
connectionPort = int.Parse(GUILayout.TextField(connectionPort.ToString()));
GUILayout.Space(5);
if(GUILayout.Button("Connect", GUILayout.Height(25)))
{
if(playerName == "")
{
playerName = "Player";
}
if(playerName != "")
{
Network.Connect(connectToIP, connectionPort);
print (levelOnServer);// off course this stays null because the level button was never clicked as a client
PlayerPrefs.SetString("playerName", playerName);
}
}
GUILayout.Space(5);
if(GUILayout.Button("Go Back", GUILayout.Height(25)))
{
iWantToConnectToAServer = false;
}
}
}
...
if I have to use RPC (which i guess i will) where and how? :-s
thanks
J.
the server works fine it deletes the needed GameObjects from the hierarchy and loads the newly needed additive
but the client doesn’t delete only loads and gives the errors…
Ok so it all works in a certain way, but i want it to work properly…
atm if a new players joins after a game or two he has all the played levels on top of each other in his game… i found this about that:
(posted by apples)
Maybe it would be even better to do it like this :
NetworkViewID Vid = GameObjectThatWillBeDestroyed.networkView.viewID;
Network.Destroy(GameObjectThatWillBeDestroyed);
Network.RemoveRPCs(Vid);
but I’m not sure where to place it and how to make sure the last level loaded by the RPC isn’t deleted…?
an other problem is that if i start a server, connect, shut down the server and start one up again with the same game instance I get this: RPC “LoadLevel” failed because networkView: “SceneID: 1”, “LevelPrefix: 0” don’t exist.
so besides from these two things it working quit well.
I don’t seems to get alot of answers here (as usual ;)) but please if some one could help me out here I can finish up my game.