Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Problem when spawn player in client

Discussion in 'Multiplayer' started by Buscatrufas, Oct 22, 2015.

  1. Buscatrufas

    Buscatrufas

    Joined:
    Apr 28, 2015
    Posts:
    4
    Hi all,

    First, sorry for my english so....i'll try to explain my problem

    I've got a game with 2 players, 1 player(host) it the host and can see himself and the client.

    In the client screen cant see nothing, only the terrain, my code in my custom Network manager :

    Code (CSharp):
    1. public class NetManager : NetworkManager {
    2.     public GameObject spawnZone;
    3.  
    4.     /*public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId){
    5.         GameObject player = Instantiate (base.playerPrefab);
    6.         player.transform.SetParent (spawnZone.transform, false);
    7.         NetworkServer.AddPlayerForConnection(conn,player, playerControllerId);
    8.         //Debug.Log("Datos del jugador añadido: " + conn);
    9.     }*/
    10.  
    11.     public override void OnServerReady (NetworkConnection conn){
    12.         base.OnServerConnect(conn);
    13.         NetworkServer.SetClientReady (conn);
    14.         GameObject player = Instantiate (base.playerPrefab);
    15.         player.transform.SetParent (spawnZone.transform, false);
    16.     }
    17.     public void StartGame(){
    18.         NetworkManager.singleton.StartHost ();
    19.     }
    20.  
    21.     public void JoinGame(){
    22.         NetworkManager.singleton.StartClient ();
    23.     }
    24.  
    25.     public override void OnClientConnect(NetworkConnection conn){
    26.        
    27.         ClientScene.Ready (conn);
    28.         ClientScene.AddPlayer (0);
    29.     }
    30. }
    If i use OnServerAddPlayer the client throw a exception because this occurs before the scene load.

    So i need to register in the server the host and the client and i need to see the both player in client.

    Need help with this guys :(

    Best Regards, Buscatrufas.
     
  2. Buscatrufas

    Buscatrufas

    Joined:
    Apr 28, 2015
    Posts:
    4
    up! Need help :(
     
  3. Buscatrufas

    Buscatrufas

    Joined:
    Apr 28, 2015
    Posts:
    4
    Up , please, anyone know about this?