I am trying to destroy monster when walking on it but each time I destroy it then i got this error:
InvalidOperationException: Collection was modified; enumeration operation may not execute. System.Collections.Generic.List`1+Enumerator[UnityEngine.GameObject].VerifyState () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:778)
TimeMap.MoveSelectedUnitTo (Int32 x, Int32 y) (at Assets/TimeMap.cs:148)
foreach(GameObject thisMonster in monsterList) {
if(thisMonster.GetComponent<Monsters>().tileX == selectedUnit.GetComponent<Unit>().tileX && thisMonster.GetComponent<Monsters>().tileY == selectedUnit.GetComponent<Unit>().tileY) {
CarryMonster(thisMonster);
counter++;
}
}
I am still trying to figure out what is wrong with this. The list certainly is not empty. I put monsters there every 5 moves.