I got a method that’s meant to destroy my objects:
private void ResetMeter()
{
lines.Clear();
var children = new List<GameObject>();
foreach (Transform child in TicksPanel.transform)
children.Add(child.gameObject);
foreach (Transform child in LinesPanel.transform)
children.Add(child.gameObject);
//foreach (var child in children)
// Destroy(child);
children.ForEach(x => Destroy(x));
}
Now, this works perfectly fine in the unity editor
but if i try to build the solution, i get an error:
‘System.Collections.Generic.List<UnityEngine.GameObject>’ does not contain a definition for ‘ForEach’ and no extension method ‘ForEach’
But if i use the regular non-linq ForEach (which i’ve commented in the code) it works fine and i can build fine.
why can’t i use the linq?
Based on some quick Internet research, I don’t think there is a ForEach method in Linq. There is, however, a ForEach method in the List class, which is the object you’re using, so that’s presumably what you mean.
I did find this discussion saying that it was removed from the “Metro” version of the library, which may be your issue.
well, you learn something new every day
thanks for the find.
didn’t really matter much, but I was just curious.
and i gotta say, the reason for removing it is just weird :S
they said it’s because you could change the list while iterating over it… but you could do the same thing in a normal ForEach loop too…
And Antistone, that’s weird, cause you have to be using linq to get that method.