Hi,
I have these two functions below, and when I run my code Function1 is being called first, then Function1 calls Function2.
Function2 returns true all the time in the current test environment, and I would expect the numbers written by Debug.Log in this order: 1, 2, 3, 4, 5, 6, 7
However the order the numbers show in the console are like this: 1, 2, 3, 4, 5, 6, 4, 5, 7
Do you have any ideas why is this happening? Why can’t the if (Function2(x, y) == true) statement recognize that Function2 returned true after it has been called?
Thanks in advance.
bool Function1() {
Debug.Log("1");
for (int x = 0; x <= (BoardManager.w - (int)rectTransform.sizeDelta.x); x++) {
Debug.Log("2");
for (int y = 0; y <= (BoardManager.h - (int)rectTransform.sizeDelta.y); y++) {
Debug.Log("3");
Function2(x, y);
Debug.Log("6");
if (Function2(x, y) == true) {
Debug.Log("7");
return true;
}
}
}
return false;
}
bool Function2(int x, int y) {
Debug.Log("4");
for (int i = 0; i < childX.Count; i++) {
if (BoardManager.cellStates[childX[i] + x, childY[i] + y] == 4) {
Debug.Log("Function2 returned false");
return false;
}
}
Debug.Log("5");
return true;
}