I've set up a grid of cubes with all random colors and am trying to check through them to ensure there are no cubes next to each other and then runs a function to go through and change them if there are more 3 cubes in a row but for some reason Unity stops responding when it tries to enforce 3 or less cubes.
void Start () {
...
bool checkColors = CheckColors ();
while (checkColors == true) {
RearrangeColors ();
}
}
bool CheckColors (){
Color colorColumnCheck = Color.red;
Color colorRowCheck = Color.red;
int colorColumnCount = 0;
int colorRowCount = 0;
bool matchingCubes = false;
for (int x = 0; x ().material.color){
colorColumnCount++;
}else{
colorColumnCount = 0;
}
if (colorColumnCount >= 2){
Debug.Log ("Found matching Vertically");
matchingCubes = true;
}
if (y == gridHeight - 1){
colorColumnCount = 0;
}
colorColumnCheck = allCubes[x,y].GetComponent ().material.color;
if (matchingCubes == true) {
return matchingCubes;
}
}
}
for (int y = 0; y ().material.color) {
colorRowCount++;
}else{
colorRowCount = 0;
}
Debug.Log ("Found matching Horizontally");
if (colorRowCount >= 32) {
matchingCubes = true;
}
if (x == gridWidth - 1){
colorRowCount = 0;
}
colorRowCheck = allCubes [x, y].GetComponent ().material.color;
if (matchingCubes == true) {
return matchingCubes;
}
}
}
return matchingCubes;
}
↧