OK so I have a method that calls itself as this was the only way I could think to get the behaviour I needed. Its a tetris clone i am making and this method is for checking for full lines across X axis.
void CheckForFullLine(int starting_Y)
{
for (int y = starting_Y; y < frozenCells.GetLength(1); y++)
{
for (int x = 0; x < frozenCells.GetLength(0); x++)
{
if (!frozenCells[x, y].isFilled)
{
CheckForFullLine(starting_Y + 1);
return;
}
if (x == CELL_COUNT_X - 1)
{
tetrisLinesThisTick++;
Debug.Log("lines this tick: " + tetrisLinesThisTick + "on tick: " + tick);
ClearLine(y);
}
}
}
}
but when i test the game, most of the time (more than 9/10 times) when you get multiple lines, the debug log says we only got 1 line in that 'tick'.
Here is the update method where at the top I set tetrisLinesPerTick to 0 at the start of each frame.
private void Update()
{
tick++;
// reset the tetris-lines this tick value:
tetrisLinesThisTick = 0;
ClearScreen();
CheckForFullLine(0);
HandleMovementAndBlockCreation();
DrawFallingPiece();
DrawFrozenBricks();
}
For example if I get 2 lines in one go, I get the debug log saying '...linesPerTick 1' twice in quick succession.
Strangely , occasionaly I do get the 2 or even 3 lines and it says the correct amount, but this is rare and i don't know how i reproduce that yet.
Another very strange thing (the relevant code might not be here for this part..) ...quite rarely one of the frozen blocks will turn grey after falling, then I can still 'use' it in game to make more lines, but it doesnt disappear like the others, then make a couple more lines using this grey block and it disappears as normal :S (well just in case you feel like helping me with this part, he is more code :P):
void ClearLine(int line)
{
// TODO: Add score
// remove complete line
for (int x = 0; x < frozenCells.GetLength(0); x++)
{
frozenCells[x, line].isFilled = false;
}
//shift all lines down // todo: figure out if its a multi-line tetris to give better scores...
for (int y = line; y < frozenCells.GetLength(1); y++)
{
for (int x = 0; x < frozenCells.GetLength(0); x++)
{
if (frozenCells[x, y].isFilled)
{
if (y > 0)
{
frozenCells[x, y].isFilled = false;
frozenCells[x, y - 1].isFilled = true;
}
}
}
}
}
For some reason, I feel it may be the recursive method i made and the fact that 'linesPerTick' value is getting set back to zero prior to the other lines being removed (in the same move), is what is causing my problem but i could be completely wrong about it!
The whole project is just one .cs file and a block texture i made in GIMP, I could paste the whole script here if you want to try it please let me know. Cheers for any help!
return
oryield
control back to it. So the error here is in your code not doing the steps you expect it to before finishing, not Unity continuing with its update tick before you've finished. \$\endgroup\$