5. Creating a game over judgment

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

If the ball falls to the bottom, the game is over.
Let’s assume that the determination method is when it touches the Wall Bottom object.
This time, since there are no colliding objects other than the ball, we omit determining the object type.
Also, it would look unnatural if the fallen Ball object remained, so we will discard it.

Adding Logic Behavior to Wall Bottom

  • Select Walls/Wall Bottom 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 Wall Bottom’s Logic Behavior

Creating the PubOnCollisionEnter.Callback 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 OnCollisionEnter Callback in the search field
  • Select PubOnCollisionEnter.Callback (Event) from the list

Editing that PubOnCollisionEnter.Callback node

  • Check Require in Target field

Creating a Collision.gameObject node

  • Drag and drop the output port of the Arg 0 field of the PubOnCollisionEnter.Callback node to open the node creation menu
  • Select the Scripts tab
  • Enter Collision gameObject in the search field
  • Select Get Collision.gameObject (Compute) from the list

Creating a GameObject.Destroy node

  • Drag and drop the output port of the Game Object field of the Collision.gameObject node to open the node creation menu
  • Select the Scripts tab
  • Enter Destroy in the search field
  • Select GameObject.Destroy(gameObject) (Action) from the list

Connecting OnCollisionEnter and GameObject.Destroy

  • Connect by dragging and dropping the execution port of the PubOnCollisionEnter.Callback node to the input port of the GameObject.Destroy node.

Creating a GameObject.SetActive node

  • Drag and drop the transition port of the GameObject.Destroy node and open the node creation menu
  • Select the Scripts tab
  • Enter GameObject SetActive in the search field
  • Select GameObject.SetActive(bool value) (Action) from the list

Editing that GameObject.SetActive node

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

Checking the behavior of game over judgment

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

Start playing and check the behavior of game over judgment.

  • Make sure that when the Ball hits the Wall Bottom object, the Ball object is destroyed and the Game Over object becomes active.

Next time

Next time we will cover 6. Creating Main Logic behavior.

Post completion

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