Skip to content Skip to sidebar Skip to footer

Unity Crashing On Play, Most Likely Infinite While Loop, But Cannot Locate Issue

thanks for reading. I'm currently building a small memory card game in Unity using C#. I have the main portion of code finished but when I press the play button on a certain scene

Solution 1:

Your deck array has at least one card in it that has _setUp set to true which would make it go in a infinite loop.

The reason it goes in a infinite loop is because it will have set all available _setUp to true and it would keep looking for _setUp that are set to false and it will never find any.

The reason you need at least 26 object that have _setUp to false is because in the nested for loop you loop 13 times and then you do that twice which gives a total of 26 loops. So you need at least 26 objects.

What you can do to make sure that they're all false is to set them all to false before entering the for loop

for(int i = 0; i < deck.Length; i++)
{
    deck[i].GetComponent<Card>().SetUp = false;
} 

Post a Comment for "Unity Crashing On Play, Most Likely Infinite While Loop, But Cannot Locate Issue"