Search Unity

I can spawn the player but he cant communicate with the server :(

Discussion in 'Multiplayer' started by tylerreece22, Nov 29, 2015.

  1. tylerreece22

    tylerreece22

    Joined:
    Jul 4, 2015
    Posts:
    11
    I am using a local WAMP server to connect everything. I get no errors when I initiate the server and then connect the client. Everything seems to run great until the player spawns and it tells me "SpawnObject for SkeletonPlayer(Clone) (UnityEngine.GameObject), NetworkServer is not active. Cannot spawn objects without an active server." Any ideas as to what is going on?

    Thank you so much for the help ahead of time.

    Code (CSharp):
    1. void OnGUI()
    2.     {
    3. if (isAtStartup)
    4.         {
    5.             GUI.Label(new Rect(2, 10, 150, 100), "Press S for server");
    6.             GUI.Label(new Rect(2, 50, 150, 100), "Press R for registered servers");
    7.             GUI.Label(new Rect(2, 90, 150, 100), "Press C for client");
    8.         }
    9.     }
    10.  
    11. public void SetupServer()
    12.     {
    13.         //connecting to my server
    14.         NetworkServer.Listen(4444);
    15.         isAtStartup = false;
    16.         Debug.Log("Server Connected");
    17. }
    18.  
    19. public void SetupClient()
    20.     {
    21.         ClientScene.RegisterPrefab(playerPrefab);
    22.  
    23.         myClient = new NetworkClient();
    24.  
    25.         myClient.RegisterHandler(MsgType.Connect, OnConnected);
    26.         myClient.Connect("127.0.0.1", 4444);      
    27.  
    28.         isAtStartup = false;      
    29.     }
    30.  
    31.     // Create a local client and connect to the local server
    32.     public void SetupLocalClient()
    33.     {
    34.         myClient = ClientScene.ConnectLocalServer();
    35.         myClient.RegisterHandler(MsgType.Connect, OnConnected);
    36.         isAtStartup = false;
    37.     }
    38.  
    39.     // client function
    40.     public void OnConnected(NetworkMessage netMsg)
    41.     {
    42.         Debug.Log("Connected to server");
    43.                 GameObject player = (GameObject)Instantiate(playerPrefab, transform.position, transform.rotation);
    44.                 NetworkServer.Spawn(player);
    45.         }
    46.     }