In tetris 2D game, how to make tetris pieces blink when a row is completed?

Hello! I’m trying to make a tetris game in unity, and in alll the tutorials I found, when a line is completed, the pieces automatically fall down. I’m very new to unity, and I don’t know how to make the pieces in a completed line “blink” for a while and then drop down. I want the game to be paused while they blink. How would you make this? Where do I start studying this?
BY the way, I followed this tutorial: https://www.youtube.com/watch?v=ODLzYI4d-J8

I downloaded Zigurous’s unity-tetris-tutorial project from GitHub and added the blink effect which appears before clearing the lines.

Tetris_Blink_Effect

Method / Theory

Zigurous’s project uses a TileMap to display the blocks.

To make the tiles blink, I change their opacity via the tilemap.SetColor() method.

Before you can manipulate a Tile’s color (tint), opacity, etc. you should make sure that its TileFlags value is not locking the color (TileFlags.LockColor). By calling the tilemap.SetFlags() method you can simply set it to TileFlags.None to give yourself full control.

I used a Coroutine to control the blink animation and yield new WaitForSeconds(..) to add a delay every time I change the opacity of the lines we wish to clear.

I modified the Piece component and made it pause the game while the blink effect is active (by “pause the game” I mean to prevent the next piece from spawning and prevent the player from controlling the piece).

Add and test the blink effect

  1. Download Zigurous’s unity-tetris-tutorial project from GitHub.
    You can download the zip-file by clicking the green Code button then choose Download ZIP.

  2. Open the project in Unity and press play. Make sure it works before you use my scripts.

  3. Download my scripts:
    Google Drive folder

  4. Back up the original Scripts folder (you’ll need this later to compare the files) then place my script files in the project’s Script folder and replace the files when asked:
    Scripts/BlinkController.cs (new)
    Scripts/Board.cs (modified)
    Scripts/Ghost.cs (modified)
    Scripts/Piece.cs (modified)

  5. Add the BlinkController component to the Board gameobject.

  6. In the Inspector, give the Piece component (on the Board gameobject) a reference to the BlinkController component.

  7. In the Inspector, give the BlinkController component (on the Board gameobject) a reference to the Board component.

  1. Set up the controls via the Board component:
    Input Move Left, Input Move Right, etc.
    These fields were added by me.

  2. Run the game.
    Play and clear a few lines.
    Adjust the blink settings via the BlinkController component in the Inspector.
    9.1: Blink Count: How many times to blink (on then off = 1 blink).
    9.2: Blink Delay Seconds: The duration between the ON and OFF states as the lines blink. 0.1 means 100ms.
    9.3: Blink Opacity: When the blink effect is visible, the lines are actually dimmed (see-through). 0.3 means 30% opaque (or 70% see-through).

Study the code

Use a diff tool to make it easier to spot the code changes.
If you don’t have a tool installed, you can use an online tool like this one:
diffchecker.com/text-compare

Example:
Drag the original Piece.cs file onto the “Original text” text box on the website.
Drag my Piece.cs file onto the “Changed text” text box on the website.
Press the “Find difference” button.

If you forgot to back up the original scripts then unzip them from the zip-file you downloaded from Zigurous’s GitHub.

Known issues

Notice that when a line blinks, not all blocks on the line blink. The blocks that are part of the piece you are placing do not blink.