private void UpdateRoster(int playerId, int level, int spriteId, string name) { //Skip if this is "us" //Debug.Log("Roster update for player ID " + playerId + ", name " + name); if (playerId == _myPlayerId) { //Debug.Log("Received roster update for yourself!"); return; } ; //If this is an existing player, update their stats foreach (GameObject go in _players) { VirtualPlayer player = go.GetComponent <VirtualPlayer>(); if (player.Id == playerId) { //If the level == -1, this player is disconnecting if (level == -1) { _players.Remove(go); //Debug.Log("Removing player " + player.Name + " from roster"); Destroy(go); return; } //Debug.Log("Updating player " + player.Name); player.UpdateStats(level, spriteId, name); return; } } //Else create a new player Debug.Log("Creating new player " + playerId + ": " + name); var newPlayer = Instantiate(VirtualPlayerPrefab); newPlayer.GetComponent <VirtualPlayer>().InitializeStats(playerId, level, spriteId, name); GameObject.DontDestroyOnLoad(newPlayer); _players.Add(newPlayer); }