Hello!
So i'm working on a multiplayer game and im stucked. I started learning the networking part about a month ago and now i have a stable basic understand about it. I want to make an authoritative server but somehow players cant see each other. I spawn the characters via Network.Instantiate but they end up with all different viewID's. The first palyer has 51 the second one who joins got 201 the third one has 301... shouldn't be it the same for all to see each other? Here is my code so far I want to keep evriting simple so i can understand it easily.
private var refreshing : boolean;
private var hostedData : HostData[];
var player : GameObject;
var myplayer : NetworkPlayer;
function Start ()
{
DontDestroyOnLoad(gameObject);
}
function Update ()
{
if(refreshing)
{
if(MasterServer.PollHostList().length >0)
{
hostedData = MasterServer.PollHostList();
refreshing = false;
}
}
}
function OnGUI ()
{
if(!Network.isClient && !Network.isServer)
{
if(GUI.Button(Rect(10,10,100,30),"Start Server"))
{
Network.InitializeServer(16,25000);
MasterServer.RegisterHost("Authiritative Testing", "Joa test game");
}
if(GUI.Button(Rect(10,50,100,30),"Find Game"))
{
MasterServer.RequestHostList("Authiritative Testing");
refreshing = true;
}
if(hostedData)
{
for(var i : int = 0; i < hostedData.length; i++)
{
if(GUI.Button(Rect(100,100,150,30), hostedData[i].gameName))
{
Network.Connect(hostedData[i]);
}
}
}
}
if(Network.isServer)
{
GUI.Label(Rect(10,10,100,100),"This is a server now! Run a nother coppy of this application if you want to join.");
}
}
///////////////////////////////////////////////Debugging!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
function OnServerInitialized ()
{
print("server initialized");
}
function OnMasterServerEvent (mse:MasterServerEvent)
{
if(mse == MasterServerEvent.RegistrationSucceeded)
{
print("Registered server");
}
}
So what i want to achive is i want a menu scene where this script is attached to an empty game object and when the player starts a server it loads the first lvl but nothing more because i want it to be only the server and then palyers have to start a nother coppy to join in.
When somebody connect i want them to load the fist level(there will be one big map) and start to paly.
I used an RPC whn somebody connected the server sent them wich level they sould load and also to set the evel prefix but players couldnt see each other. then i tried it whitout the level loading so players would instantiate on the menu level but the result was the same. I know there is a way to set the viewID manually but i couldnt find a tutorial or a sample code on how to do it.
If someone could explain it to me or show an example that would be great!
Thank you for your answers!
↧