My grid is on an array and I iterate through each grid tile to check to see if it is null and if the one above it isn't it will drop the block to the one below.
The code worked perfectly fine when I did this instantly, but once I added a coroutine so I drop the blocks slowly it stopped working. I'm fairly sure it's because the loop is checking blocks before they are set properly but I'm not sure how to go about fixing that problem.
private void UpdateBoard()
{
// Need to figure out how to adjust my grid objects when a word has been destroyed.
for (int x = 0; x < grid.width; x++)
{
for (int y = 0; y < grid.height - 1; y++)
{
if (grid.tiles[x, y] == null && grid.tiles[x, y + 1] != null)
{
StartCoroutine(BlockFall( x, y + 1 ));
// grid.tiles[x, y + 1].transform.position = new Vector2(grid.tiles[x, y + 1].transform.position.x, grid.tiles[x, y + 1].transform.position.y - 1);
}
}
}
}
public IEnumerator BlockFall(int posX, int posY)
{
float startY = 1;
grid.tiles[posX, posY].pos.y = grid.tiles[posX, posY].pos.y - 1;
grid.tiles[posX, posY - 1] = grid.tiles[posX, posY];
while(startY > 0)
{
startY -= 0.25f;
grid.tiles[posX, posY].transform.position = new Vector2(grid.tiles[posX, posY].transform.position.x, grid.tiles[posX, posY].transform.position.y - 0.25f);
yield return new WaitForSeconds(0.1f);
}
grid.tiles[posX, posY] = null;
}
Those are the two functions that are important. It's a bit messy right now perhaps, but it worked.
What happens now, is that the first block will fall, but the ones above it won't. That was working when instant though.