Add a Simple Enemy
Last updated
Last updated
Before adding a new enemy, make sure you have all the components needed: 1. Sprite sheet with walk animation that was correctly set up. 2. Animation based on the sprite sheet with an animator component.
If you are not sure how to prepare sprite sheets or create animations, see this documentation. Additionally, you can look up the parameters of an existing sprite sheet, animation or animator.
Every enemy needs its own prefab. For ease of use, we would recommend copying any existing enemy prefab, instead of creating one from scratch:
Make sure to rename said prefab according to your needs.
If you don't want to add a new enemy, but instead simply change an existing one, you can skip this step.
Open your newly created prefab. There you will see a following structure:
Parent object has its behavior script, collider and rigid body. Its child object (enemy_name) corresponds to enemy graphics - sprite renderer and animator. Shadow object is a universal prefab that draws a decorative shadow underneath the enemy.
Click on the child object, and navigate to the Sprite Renderer component in the inspector
Click on the Sprite field, and choose a sprite from your desired sprite sheet. Usually its the very first sprite. This is mostly needed for clearer representation.
If the sprite you chose appears much larger or smaller than you expected, set a different Pixels Per Unit value in the sprite sheet's settings.
Next, navigate to the animator component below:
Click on the Controller field, and choose the corresponding animator object for the enemy.
In the Parent Object, navigate to the Collider component:
Here you can change Offset and Radius parameters to better fit your newly changed sprite.
Now you will need to add the enemy to the database.
Navigate to the EnemyDatabase.cs script, and open it.
Scroll to the bottom. There you will find an Enum, listing every enemy in order.
In a new row below the last entry, type your Enemy name in camel code, without using spaces.
If you don't want to add an enemy, but instead changed an existing one in Step 2, simply rename the enemy you changed in the list above.
The format should be like in the picture above - "EnemyName = Order number, ". Make sure that every entry has a unique number.
After making desired changes, save the script.
Now, navigate to the Scriptable file located here:
There you will find a list of all existing registered enemies. To add your new enemy, press the + icon on the bottom of the list - a new entry will spawn. Here you need to assign the name of your enemy, and the prefab that you created in the Step 2.
Additionally you can assign a preview image for your enemy. It can be a sprite from its sprite sheet, or anything else. It will be useful to clearly distinguish enemies in the Stage Creator later on.
If you don't have an image or don't want it at all, you can choose None in the Icon field.
Under the enemy entry there will be an additional list called Enemy Drop. There you can tune drop rate for every item available in Drop Database.
Finally, to make the enemy behave how you like, its recommended to change its Settings in the prefab under Enemy Behavior component:
Additionally, every enemy by default has a universal death animation using custom shader. You can view the shader by clicking on the material in Material field of the enemy graphics:
There, you can change the parameters to fit your needs.
If you are not satisfied with this shader effect, you can assign a different material in the field above.