I have this code that removes a player if the player is not alive, but I figured the problem is to do with the foreach
loop. I've seen solutions involving making new lists, but I cannot see how I can apply it to my code. Can anyone please shed some light?
private Dictionary<int, Player> numPlayers = new Dictionary<int, Player>();
private void CheckPlayers()
{
foreach (Player player in numPlayers.Values)
{
if (!player.isAlive)
{
canvas.Children.Remove(player.hand);
numPlayers.Remove(player.id); // breaks here
}
}
}