In the last post, we added an attack cooldown for the player attack. Now it’s time to move on from the player and begin prototyping an enemy!
Our challenge is to create an enemy prefab with a 3D primitive, a material to make it stand out from the player, and provide basic movement behavior.
Let’s go started.
Create The Enemy
I’ll use another Cube for the enemy but change the transform scale to 0.75. Let’s make sure the enemy stands out in the prototype by creating a new Material and giving it a color of #F16868.
Add Enemy Movement
Now let’s add some movement by creating a new
Enemy script and attaching it to our Enemy GameObject. I want the enemy to move down the screen with a speed configurable via the inspector.
When the enemy goes offscreen, let’s reposition it to be in a random horizontal position and above the screen so that it will downward again in a new position. This way, the number of enemies will increase over time, and we’ll reuse any that the player has not destroyed.
Finally, I’ll make this a prefab that we can use to instantiate enemies later in the prototype.
We now have an
Enemy prefab that knows how to move and reposition itself in a new random horizontal position and offscreen vertically.
Stay tuned for the next post.