IEnumerator Dungeon() {
int X = Random.Range (-3, 3)*2;
int Y = Random.Range (-2, 2)*2;
Vector2 pos = new Vector2 (X, Y);
if (Vlist.Contains (pos) == true) {
print ("repeated");
yield return Dungeon (); //this is what crashes it
}
Vlist.Add (pos);
if (i == Rooms)
StopCoroutine (Dungeon ());
else {
i++;
Instantiate (Room, pos, transform.rotation);
yield return Dungeon();
}
}
Essentially what it's supposed to do is randomly generate a dungeon map. It works pretty well until i added the vector list that was supposed to stop it from repeating tiles but instead it instantly crashes my game. Is it only because it causes an "infinite" loop by accident? Or is it something else?
thanks for your time <33
↧