private void assignTeam(Player player) { Layers layer = Layers.Team1Actor; if (this.firstPlayerJoined) { layer = Layers.Team2Actor; } this.firstPlayerJoined = true; player.Team = layer; Debug.Log("Assigned layer: " + layer); PlayerRPC.SetPlayerTeam(player.ID, (int)player.Team); }
private void OnPlayerConnected(NetworkPlayer networkPlayer) { if (!this.firstPlayerJoined) { ObjectRPC.LoadLevel(0); } else { ObjectRPC.LoadLevel(networkPlayer, 0); } Debug.Log("A new player has joined."); Debug.Log("Current number of players: " + base.Players.Count); foreach (Player p in base.Players.Values) { PlayerRPC.NewPlayerJoined(networkPlayer, p.NetworkPlayerInfo, p.ID); } // Generate a viewID for the new player. NetworkViewID viewID = Network.AllocateViewID(); // Notice everyone that the new player has joined. PlayerRPC.NewPlayerJoined(networkPlayer, viewID); Player newPlayer = base.Players[viewID]; // Tell the new player the teams of all the other players. foreach (Player p in base.Players.Values) { if (!(p.ID == base.NetworkControl.LocalViewID || p.ID == newPlayer.ID)) { PlayerRPC.SetPlayerTeam(newPlayer.NetworkPlayerInfo, p.ID, (int)p.Team); } } this.assignTeam(newPlayer); // Sync the existing game world with the new player. this.CurrentLevel.SyncNewPlayer(newPlayer); }