I'm trying to do a check and run a method until it's true.
public struct Letter
{
public string letter;
}
private void DoStart()
{
UsedIndexes.Clear();
BuildGoodGame();
}
List<Letter> usedLetter = new List<Letter>();
private void BuildGoodGame()
{
usedLetter.Clear();
Letter temp;
for (int i = 0; i < Couch.Length; i++)
{
do
{
couchIndex = CouchNameRandom.getRandom();
Couch[i].setCurrentChildIndex(couchIndex);
MisingLetterScript thisLetter = Couch[i].CurrentChild.GetComponent<MisingLetterScript>();
string s = thisLetter.Letter;
temp = new Letter
{
letter = s
};
} while (UsedNames.Contains(couchIndex) || usedLetter.Contains(temp));
UsedNames.Add(couchIndex);
usedLetter.Add(temp);
}
}
I want to run this code twice, the first time it runs ok, it goes totally perfect. The second time, I do Invoke("DoStart", 1f) and it's no longer running, Generally Freezing Unity. The whole issue is in the returnable method, which checks if the list contains the duplicate. I do not understand why the first time works fine, then after I call again the DoStart method, it is freezing. Help!! thank you.