private void HandleClientDisconnect(ulong clientId) { for (int i = 0; i < lobbyPlayers.Count; i++) { if (lobbyPlayers[i].ClientId == clientId) { lobbyPlayers.RemoveAt(i); break; } } }
private void AssignPlayerColorServerRpc(ulong ulClientID) { // Get the clients network object, return if not valid. if (!NetworkManager.Singleton.ConnectedClients.TryGetValue(ulClientID, out NetworkClient ncClient)) { return; } // Get the clients player object, return if not valid if (!ncClient.PlayerObject.TryGetComponent <Player>(out Player oPlayer)) { return; } // new color variable for assigning random color Color cRandomColor = Color.white; // if mn_acAvailablePlayerColors count is at least 2 if (mn_acAvailablePlayerColors.Count > 1) { // Get a random color and assign to color variable cRandomColor = mn_acAvailablePlayerColors[Random.Range(0, mn_acAvailablePlayerColors.Count)]; // loop through mn_acAvailablePlayerColors array for (int i = 0; i < mn_acAvailablePlayerColors.Count; i++) { // if the random color is in the array remove it if (mn_acAvailablePlayerColors[i] == cRandomColor) { mn_acAvailablePlayerColors.RemoveAt(i); } } } // if only one value is left in mn_acAvailablePlayerColors else if (mn_acAvailablePlayerColors.Count == 1) { // Assign last color in array to the color variable cRandomColor = mn_acAvailablePlayerColors[0]; // Remove the final value from the array, making it empty mn_acAvailablePlayerColors.Remove(cRandomColor); // Loop through all colors and re-initialize mn_acAvailablePlayerColors array for (int i = 0; i < m_acAllPlayerColors.Count; i++) { mn_acAvailablePlayerColors.Add(m_acAllPlayerColors[i]); } } // else if the mn_acAvailablePlayerColors count is 0 else { // Print error message, change color of player to black to make it clear there is a problem Debug.Log("Error: mn_acAvailablePlayerColors is Empty?"); cRandomColor = Color.black; } // Send color to player object oPlayer.SetBodyColorServerRpc(cRandomColor); }