4. Creating a game clear judgment

If you haven’t completed the previous steps yet, please go through the previous tutorial on How to create Block Breaking first.

The game is cleared if all Block objects are destroyed.
All Block objects are placed in the children of the Blocks object, so let’s clear it when the number of child objects of the Blocks object is 0.

Adding Logic Behavior to Blocks

  • Select Blocks object
  • Click the Add Component button in the Inspector window
  • Select Logic Toolkit/Logic Behavior and add Logic Behavior component
  • Click the Logic Behavior Edit button to open the Logic Editor window

Edit Blocks’ Logic Behavior

Creating an Int Equals node

  • Delete Start node
  • Click on the graph and press the Spacebar while it has focus to open the node creation menu
  • Select the Scripts tab
  • Enter Int Equals in the search field
  • Select Int Equals (Event) from the list

Creating the Transform.childCount node

  • Drag and drop the input port of the Value 1 field of the Int Equals node to open the node creation menu
  • Select the Members tab
  • Enter Transform childCount in the search field
  • Select childCount [Get] of UnityEngine.Transform from the list
  • Select Compute from the node type selection menu

Creating a GameObject.SetActive node

  • Drag and drop the execution port of the Int Equals node and open the node creation menu.
  • Select the Members tab
  • Enter GameObject SetActive in the search field
  • Select SetActive(bool value) of UnityEngine.GameObject from the list
  • Select Action from the node type selection menu

Editing that GameObject.SetActive node

  • Set Canvas/Game Clear object in Target field
    You can set it in one of the following ways:
    • Change Self to Value and set the Canvas/Game Clear object in the Object field
    • Leave it as Self and drag and drop the Canvas/Game Clear object from the Hierarchy window into the Target field
  • Check Value field

Check behavior of clear judgment

Once you’ve done this, your graph will look like this:

Start playing and check the behavior of clear judgment.

  • Confirm that the Game Clear object becomes active when all blocks are destroyed by hitting them with the ball.

Next time

Next time we will cover 5. Creating a game over judgment.

Post completion

If you would like to post on social media about the completion of the work up to this point, click here.