🦇
Monster Survivors Template Documentation
  • Welcome
  • CHARACTER
    • Add a Character
    • Starting Ability
  • Stages
    • Stage Creator
    • Tracks And Clips
    • Stage Settings
    • Create a Stage
  • Enemies
    • Simple Enemies
    • Ranged Enemies
    • Bosses
    • Add a Simple Enemy
    • Add a Boss
  • Abilities
    • Ability Types
    • Abilities System Structure
    • Add Abilities
  • Upgrades
    • Upgrade Types
    • Upgrades System Structure
    • Add an Upgrade
  • Game structure
    • Main Menu Scene
    • Game Scene
  • Input
    • Input System
    • Menu Navigation
  • Known Issues
    • IOS Build
  • Testing
    • Abilities Testing Overlay
    • Presets
Powered by GitBook
On this page
  1. Enemies

Add a Simple Enemy

PreviousBossesNextAdd a Boss

Last updated 4 months ago

1

Preparation

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.

2

Prefab creation

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.

3

Prefab set-up

  1. 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.

  1. Click on the child object, and navigate to the Sprite Renderer component in the inspector

  2. 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.

  1. Next, navigate to the animator component below:

  2. Click on the Controller field, and choose the corresponding animator object for the enemy.

  3. In the Parent Object, navigate to the Collider component:

  1. Here you can change Offset and Radius parameters to better fit your newly changed sprite.

4

Registering an enemy

Now you will need to add the enemy to the database.

  1. Navigate to the EnemyDatabase.cs script, and open it.

  1. Scroll to the bottom. There you will find an Enum, listing every enemy in order.

  1. 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.

  1. After making desired changes, save the script.

  2. 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.

  1. 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.

  1. 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.

5

Enemy Customization

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.

6

Finish

Now, if you did everything correctly, the enemy should behave and spawn accordingly.

On how to see the enemies in action, take a look at

Unity Learn
Creating a new stage
Copying existing prefab
Enemy prefab hierarchy
Enemy Sprite Renderer
Enemy Animator Component
Enemy Collider Component
Database Script
Enum with enemies
Enemy Database
Enemies List in the database
Custom enemy material