- Home /
Spawn player OnServerInitialized
Hello
I'm trying to instantiate a player when the scene is loaded, but it don't work, what i'm tring to do is, the player choose the level he want to play from the main menu and after that the scene is loaded, the player will be instatiate. but it will not, the debug work but not the instatiation does anyone know to fix it ?
Thank you
Here the code to spawn the player
void OnServerInitialized()
{
Debug.Log("I m connected server");
playerR = Network.Instantiate(player1,transform.position,Quaternion.identity,0) as GameObject;
playerR.name = "R3D";
Camera[] cam= playerR.gameObject.GetComponentsInChildren<Camera>();
foreach(Camera camer in cam) {
camer.enabled=true;
}
EnablePlayer(playerR);
//isConnected=true;
}
and here when i load the level from the menu
if ( GUI.Button(ResizeGUI(new Rect(1000.0f,400f,400.0f,60.0f)), "Lunch Server", ButtonStyle))
{
Network.InitializeSecurity();
Network.InitializeServer(int.Parse("1"), int.Parse(port), !Network.HavePublicAddress());
MasterServer.RegisterHost (gameName, serverName+"( Level "+displayLevel+" )");
networkView.RPC( "LoadLevelOn", RPCMode.AllBuffered, selectedLevel);
}
[RPC]
void LoadLevelOn(int selectedLevel)
{
Application.LoadLevel(selectedLevel);
}
Sorry but the debug don't work either, it work only when i initialize the server from the scene and not when i load it from the main menu, if anyone does know how to fix it
Thank you
Your answer
Follow this Question
Related Questions
Networking: how to sync NetworkViewIDs for level objects on peers? 4 Answers
Instantiate prefab and passing parameter 1 Answer
Unet NetworkServer.Spawn() not working 5 Answers
Network.Instantiate issues - GameObject ownership and network views? 0 Answers
UNet - How do I make Network.Spawn not show the prefab to the user that called it? 1 Answer