i feel like such a idiot asking this question but what could possibly be wrong with this code its in js
/ or ++
for(var i = 0; i <= SelectedObjects.Count; i+=1){
var Obj : GameObject = SelectedObjects_;_
Obj.GetComponent(Renderer).material.color = Color.white;
SelectedObjects.RemoveAt(i);
Refresh();
}
but it does not remove all items in the array?
In general you shouldn’t be removing elements from a list while you’re iterating over it. Is there any reason why you can’t wait until the for loop finishes before you clear the list?
Another option is to iterate from the back of the list to the front, instead of from front to back, ie:
for (var i = SelectedObjects.Count - 1; i >= 0; i--) {
var Obj : GameObject = SelectedObjects;
Obj.GetComponent(Renderer).material.color = Color.white;
SelectedObjects.RemoveAt(i);
Refresh();
}