Setting up sprites
We will now add enemy scripts and set up sprites.
First on our agenda is setting up the Enemy prefab and script. Let's take a look at the Enemy prefab. The prefab was imported with all of the starting materials in Chapter 2
. Just in case you need an extra copy of the Enemy prefab though, there will be an import file in the accompanying Chapter 7
files.
The Enemy prefab looks a lot like the Player prefab. Both the Enemy
and Player
classes inherit from the Moving Object
class. This means the enemy movement and animations are going to be processed in a similar way to the Player
class. This generally means the prefab structure will have to be similar.
Requirements for our Enemy prefab include:
A Sprite Renderer
An Animator
A Box Collider 2D
A Rigid Body 2D
The Enemy Script
Also, be sure that these options are selected in your Enemy prefab:
Set the tag to Enemy
Set the layer to BlockingLayer
In the Sprite Renderer component, set the Sorting Layer field to Units
In the Animator...