- Home /
Networking Help Needed
I am making a CO-OP action game. but when client connects it is out of sync with server.
All items have a Network View ID and all Instatitates and Destroys are Network.Instantiate and Network.Destroy.
I have tried 2 main solutions. Firstly launching the player directly into the Level, but client cannot see anything instantiated before they joined, and all further instantiated objects throw an View ID Error (Code Below)
I have also tried the solution in the Unity Docs. Network Level Loading However I attach the script to an object in Level 1 and it creates a loading screen, but when you click on the button to access the level it just creates a new object in the scene which is a duplicate of itself and doesn't load anything.
Been at this for 2 day solid so any help would be appreciated.
var playerPrefab:GameObject;
var gameName:String = "ElusiveByteSpaceWars";
var roomName:String = "Default";
var refreshing:boolean = true;
private var hostData:HostData[];
var btnX:float;
var btnY:float;
var btnW:float;
var btnH:float;
function Start (){
btnX = Screen.width * 0.03;
btnY = Screen.height * 0.03;
btnH = Screen.width * 0.2;
btnW = Screen.width * 0.2;
}
function Update () {
if(refreshing){
if(MasterServer.PollHostList().Length > 0){
refreshing = false;
Debug.Log(MasterServer.PollHostList().Length);
hostData = MasterServer.PollHostList();
}
}
}
function StartServer(){
Network.InitializeServer(32, 25000, !Network.HavePublicAddress);
MasterServer.RegisterHost(gameName, "Space Wars Room - " + roomName, "This is a test for a game");
}
function OnMasterServerEvent(mse:MasterServerEvent){
if (mse == MasterServerEvent.RegistrationSucceeded){
Debug.Log("Registered on Master Server");
}
}
//Messages
function OnServerInitialized(){
Debug.Log("Server Initialized");
Application.LoadLevel("Level 1");
}
function OnConnectedToServer(){
Application.LoadLevel("Level 1");
}
function RefreshHostList(){
MasterServer.RequestHostList(gameName);
refreshing = true;
}
//GUI
function OnGUI (){
if(!Network.isClient && !Network.isServer){
if(GUI.Button(Rect(25, 25, 100, 100), "Start Server")){
Debug.Log("Starting Server");
StartServer();
}
GUI.Label (Rect (145, 25, 200, 25), "Name your Game");
roomName = GUI.TextField (Rect (145, 50, 150, 25), roomName, 40);
if(GUI.Button(Rect(25, 125, 100, 100), "Refresh Hosts")){
Debug.Log("Refreshing");
RefreshHostList();
}
if(hostData){
for(var i:int = 0; i< hostData.Length; i++){
if(GUI.Button(Rect(btnX *1.5 + btnW, btnY *1.2 +(btnH * i), btnW * 3, btnH *0.5), hostData[i].gameName)){
Network.Connect(hostData[i]);
}
}
}
}
}
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Client not loading into the same scene as host 0 Answers
Authoritative Server / Player Communication 1 Answer
UNet Network Transform not Sync 1 Answer
Multiplayer Level Loading 1 Answer