private IEnumerator UpdatePathsRecursively(GamePiece currentPiece, bool[,] checkedPieces, bool delayBtwPieces = true) { checkedPieces[currentPiece.XPos, currentPiece.ZPos] = true; bool alreadyGlowing = true; if (!currentPiece.IsGlowing()) { currentPiece.InWinPath(true); alreadyGlowing = false; } // End piece found if (currentPiece.pieceType == GamePiece.PieceType.END) { endCount++; } // Loop through sides of current piece for (int i = 0; i < 4; i++) { // Check if current side of current piece is open if (currentPiece.CheckConnections()[i]) { // Check if connection piece exists, hasn't yet been checked, and is open on corresponding side if (DoesPieceExist(currentPiece.XPos + CON_MATRIX[i, 0], currentPiece.ZPos + CON_MATRIX[i, 1]) && !checkedPieces[currentPiece.XPos + CON_MATRIX[i, 0], currentPiece.ZPos + CON_MATRIX[i, 1]] && gamePieces[currentPiece.XPos + CON_MATRIX[i, 0], currentPiece.ZPos + CON_MATRIX[i, 1]].CheckConnections()[CON_MATRIX[i, 2]]) { // Continue to next piece //Debug.Log("Continuing to piece (" + (currentPiece.XPos + CON_MATRIX[i, 0]) + "," + (currentPiece.ZPos + CON_MATRIX[i, 1]) + ")"); if (delayBtwPieces && !alreadyGlowing) { yield return(new WaitForSeconds(connectedAnimWait)); } yield return(UpdatePathsRecursively(gamePieces[currentPiece.XPos + CON_MATRIX[i, 0], currentPiece.ZPos + CON_MATRIX[i, 1]], checkedPieces, delayBtwPieces)); } } } }