Game Development Reference
In-Depth Information
Now you have a setup where the enemy can walk back and forth on a platform and
switch directions before walking off of the ledge. With all the scripts in place, put the
enemy on a platform and hit play. Now you can watch them walk back and forth!
Regardless of what platform you put the enemy on, they will now walk back and
forth across it.
Pro tip
With a solid knowledge of Unity's programming system, you
could easily customize an enemy so that when it reaches the end
of a platform, they will look for another nearby platform and then
jump to it, rather than only switching directions. Try adding some
additional logic and see what else you can make the enemy do!
Make it deadly
As you may have noticed, walking into the enemy currently just messes with the
player's collision system. In fact, that's a little ugly; so, let's clean it up. All that we
need to do here is create a collision mask . Start by going to the Tags & Layers panel
of Unity, just like you did before, and add a layer for both player and enemy. Set the
layer on the player to be Player and the layer on the enemy to be... you guessed it,
Enemy . When you apply the layer to either object, it will ask if you want to apply to
the child objects—go ahead and say Yes .
With the proper layers specified on the objects, we need to set the Layer Masking.
Go to Edit | Project Settings | Physics 2D and set the checkboxes so that Player
and Enemy do not collide with each other, as shown in the following screenshot:
 
Search WWH ::




Custom Search