Example #1
0
    public override void OnServerAddPlayer(NetworkConnection conn)
    {
        if (modoServidor == ServidorPartida)
        {
            if (SceneManager.GetActiveScene().path == lobbyScene && rondaAJugar <= maxRondas)
            {
                RoomPlayer roomPlayerInstance = Instantiate(roomPlayerPrefab);
                if (indexColoresServidor < maxPlayers)
                {
                    PlayerColorMessage msg = new PlayerColorMessage();
                    msg.Color = coloresServidor[indexColoresServidor];
                    indexColoresServidor++;
                    conn.Send <PlayerColorMessage>(msg);
                }


                NetworkServer.AddPlayerForConnection(conn, roomPlayerInstance.gameObject); // Esto se encarga de spawnearlo en todos los clientes también
                RoomPlayers.Add(roomPlayerInstance);

                if ((numPlayers == maxPlayers && rondaAJugar < maxRondas) || (numPlayers == maxPlayers / 2 && rondaAJugar == maxRondas))
                {
                    NextRound();
                }
            }
        }
        else if (modoServidor == ServidorCombate)
        {
            if (SceneManager.GetActiveScene().path == lobbyScene)
            {
                RoomPlayer roomPlayerInstance = Instantiate(roomPlayerPrefab);
                NetworkServer.AddPlayerForConnection(conn, roomPlayerInstance.gameObject); // Esto se encarga de spawnearlo en todos los clientes también
                RoomPlayers.Add(roomPlayerInstance);

                if (numPlayers == maxPlayers)
                {
                    StartGame();
                }
            }
        }
    }