So I am making buttons with this code
` void gcListItem(Texture strItemName)
{
GUILayout.BeginHorizontal();
if(GUILayout.Button((strItemName), GUILayout.Height(100))){
Debug.Log(strItemName.name);
Buttons.Remove(strItemName);
}
GUILayout.EndHorizontal();
}
void gcListBox()
{
GUILayout.BeginVertical(GUI.skin.GetStyle("Box"));
GUILayout.BeginArea (new Rect (40,230,400,300));
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(250), GUILayout.Height(250));
foreach(Texture _texture in Buttons){
gcListItem(_texture);
}`
The problem is that when I click on the button I get this error :
[InvalidOperationException: Collection was modified; enumeration operation may not execute.
System.Collections.Generic.List1+Enumerator[UnityEngine.Texture].VerifyState () System.Collections.Generic.List
1+Enumerator[UnityEngine.Texture].MoveNext ()]
The code that causes this error is Buttons.Remove(strItemName);
The question is how do I fix it please Help.