private void OnCreateCharacter(NetworkConnection conn, CreateCharacterMessage message) { if (currentPlayers == maxPlayers) { conn.Disconnect(); return; } int character = message.character; if (character < 0) { character = AvailableCharacter; } int roleInt = message.role; if (roleInt < 0) { roleInt = Random.Range(0, availableRoles.Count); } Role role = roles[availableRoles[roleInt]]; availableRoles.RemoveAt(roleInt); GameObject player = Instantiate(spawnPrefabs[character]); PlayerController playerController = player.GetComponent <PlayerController>(); playerController.Role = role; playerController.PlayerNumber = availableSpots[0]; playerController.PlayerName = message.playerName; availableSpots.RemoveAt(0); NetworkServer.AddPlayerForConnection(conn, playerController.gameObject); players.Add(conn, playerController); playerController.TargetSetLocalPlayer(conn, maxPlayers); if (++currentPlayers == maxPlayers) { GameController gc = FindObjectOfType <GameController>(); gc.SetMatch(players.Values.ToArray()); } }