Step 6

Explanation of the patrolling enemy script

Here's how the patrolling enemy script should look:

There's one block in here that you won't have seen before: that's the "set scale x" block from Transform. The reason we are scaling the enemy by -1 on the x axis is because we want it to be flipped over to face the player. If we scaled it by 2 it would be twice as wide, but scaling it by a negative number flips it (you can also scale y if you want to flip it the other way).

Double check that you've placed all these blocks as shown. Once you're done, save this script and name it Patrolling enemy.

Make sure to apply this script to each of your patrolling enemy game objects.

Play your game to find out if it works. Can you modify this script to have the enemies patrolling in different ways?

results matching ""

    No results matching ""