Hello!
So I am trying to make a Hack and Slash and I am running in to a problem with my enemies. I create them within an arraylist but when I come to kill one, my player hits it and then I get the following error : InvalidOperationException: List has changed. Haven’t had much chance finding any solutions.
Thanks.
enter code here
public class PlayerAttack : MonoBehaviour
{
public int minimumDistance = 2;
public static ArrayList allennemys;
void Start()
{
allennemys = new ArrayList( GameObject.FindGameObjectsWithTag("Ennemy") );
}
void Update ()
{
foreach(GameObject go in allennemys)
{
if(Input.GetMouseButtonDown(0))
{
if(Vector3.Distance(transform.position, go.transform.position) < minimumDistance)
{
Debug.Log("Bitch Please!");
allennemys.Remove(go);
}
}
}
}
}