I’m getting this problem, using Ling filter in a list. bestBoughtUpgrade should be the max upgradeID, what i’m doing wrong?
InvalidOperationException: Operation is not valid due to the current state of the object
System.Linq.Enumerable.Iterate[ModuleUpgrade,Int32] (IEnumerable`1 source, Int32 initValue, System.Func`3 selector)
System.Linq.Enumerable.Max[ModuleUpgrade] (IEnumerable`1 source, System.Func`2 selector)
//Code
public void setMaxUpgrades() {
foreach (Module module in modules) {
int bestBoughtUpgrade = module.modUpgrades.Where(u => u.bought == true).Max(id => id.upgradeID);
playerc.transform.GetChild(1).transform.GetChild(bestBoughtUpgrade).GetComponent<SpriteRenderer>().color = modules[module.moduleID].modUpgrades[bestBoughtUpgrade].upgradeColor;
}
}