2D Game Kit

We are now going to add a pushable box to our level, which can be used for the following purposes:

  • As a floating platform:

  • To maintain the pressure on a pressure pad:

  • As pushable boxes for puzzles:

  • As an environmental weapon that can be used against enemies:

In order to do this, we have to head to 2DAssets | Prefabs | Interactables and add the pushable box. This box has the Pushable (Script), which will allows us to move the box from one place to another.

It will also automatically float whenever we throw it into the water. We will later see how to use it to squish enemies.

If we want to make an object of our own pushable, we will need to add the same Pushable component, as shown in the following screenshot:

There are some references that we will need to create and add in order to make this script work. To do this, let's go through the following steps:

  1. Create three empty GameObject instances and make them children of the object with the Pushable component, as shown in the following screenshot:

  1. Change the names of the children to LeftPosition, RightPosition, and AudioSource, as shown in the following screenshot:

  1. Move the LeftPosition object to the left limit of the box and the RightPosition object to the right limit of the box. After that, add an Audio Source component to the AudioSource child.
  1. Click on the parent object and add the following references to the Pushable component:
Player Pushing Right Position Drag and drop the RightPosition child
Player Pushing Left Position Drag and drop the LeftPosition child
Pushable Position Drag and drop the parent object Transform component by clicking on the component name and dragging to the field
Pushable Audio Source Drag and drop the AudioSource child to this field
Starting Push Clip Select the clip that will play the noise when the pushing starts
Loop Push Clip Select the clip that will play the noise while pushing
End Push Clip Select the clip that will play the noise when the pushing ends

Once we have done this, the component should resemble the following screenshot:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.96.247