3. Creating Block behavior

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

Create Block behavior.
Block has the behavior of destroying its own object if something hits it.
This time, since there is nothing to hit other than the ball, we will omit the judgment of the hit object.

The Block object is prepared as a prefab, and it is assumed that the object will be reused.
Instead of using Logic Behavior directly, let’s reuse the behavior by playing the Logic Asset with Logic Player.

Creating assets

Create Logic folder

Create a folder to save Logic Toolkit related assets.
You can name it anything you like, but this time we’ll create a folder called Logic.

  • Select the BlockBreaking folder in the Project window
  • Click the + button
  • Select Folder from the menu
  • Renamed to Logic

Creating a Logic Asset

  • Select the Logic folder in the Project window
  • Click the + button
  • Select Logic Toolkit/Logic Asset from the menu
  • Renamed to Block Logic
  • Click the Edit button in Logic Asset to open the Logic Editor window

Edit Block Logic

Creating a 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 GameObject.Destroy node

  • Drag and drop the execution port of the PubOnCollisionEnter.Callback node and open the node creation menu
  • Select the Scripts tab
  • Enter Destroy in the search field
  • Select GameObject.Destory(gameObject) (Action) from the list

Unity’s Destroy method is Object.Destroy(Object), but since it would be more convenient to also specify a Self object with InputGameObject, we have prepared a built-in script to do GameObject.Destroy(GameObject).

Group (optional)

  • With all the two created nodes selected, press the G key to create a group node.
  • Renamed to OnCollisionEnter
  • Click the icon that appears when you hover over the group node
  • In the comments, enter If this block is hit by something (only the ball this time), it will destroy itself.

Set Logic Player to Block

Open Block in prefab mode

  • Double-click the Assets/BlockBreaking/Prefabs/Block prefab in the Project window

Add Logic Player

  • Select Block object in Hierarchy window
  • Click the Add Component button in the Inspector window
  • Select Logic Toolkit/Logic Player from the component addition menu and add the Logic Player component.

Editing that Logic Player component

  • Set Block Logic in Asset field

Exiting prefab mode and saving

  • Click the < button in the header of the Hierarchy prefab
  • A dialog will appear asking if you want to save, so click the Save button

Check Block behavior

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

Start playing and check the behavior of Block.

  • Confirm that the Block object is destroyed when the Ball hits it.

Next time

Next time we will cover 4. Creating a game clear judgment.

Post completion

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