# Add a Simple Enemy

{% stepper %}
{% step %}

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

<mark style="color:yellow;">If you are not sure how to prepare sprite sheets or create animations, see this</mark> [Unity Learn](https://learn.unity.com/tutorial/introduction-to-sprite-animations#) <mark style="color:yellow;">documentation.</mark> \
\ <mark style="color:yellow;">Additionally, you can look up the parameters of an existing sprite sheet, animation or animator.</mark>
{% endstep %}

{% step %}

### 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:

<figure><img src="/files/nvZFo2ea8LSCYg2GWHLc" alt="" width="149"><figcaption><p>Copying existing prefab</p></figcaption></figure>

Make sure to rename said prefab according to your needs.

<mark style="color:yellow;">If you don't want to add a new enemy, but instead simply change an existing one, you can skip this step.</mark>
{% endstep %}

{% step %}

### Prefab set-up

1. Open your newly created prefab. There you will see a following structure:

<figure><img src="/files/Jj2Q5y0Pmx66osw1rtch" alt="" width="184"><figcaption><p>Enemy prefab hierarchy</p></figcaption></figure>

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.

2. Click on the child object, and navigate to the Sprite Renderer component in the inspector<br>

   <figure><img src="/files/Rz0dAyGrAuHDYE7rtF1x" alt="" width="330"><figcaption><p>Enemy Sprite Renderer</p></figcaption></figure>

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

<mark style="color:yellow;">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.</mark>

4. Next, navigate to the animator component below:<br>

   <figure><img src="/files/mqi86fx1yGsukZSZAHYS" alt="" width="326"><figcaption><p>Enemy Animator Component</p></figcaption></figure>

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

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

<figure><img src="/files/1ovXyQxFYmZPyXQaaBYM" alt="" width="332"><figcaption><p>Enemy Collider Component</p></figcaption></figure>

7. Here you can change Offset and Radius parameters to better fit your newly changed sprite.&#x20;
   {% endstep %}

{% step %}

### Registering an enemy

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

1. Navigate to the EnemyDatabase.cs script, and open it.&#x20;

<figure><img src="/files/LdDYYq1VG4tsI02aECKo" alt="" width="294"><figcaption><p>Database Script</p></figcaption></figure>

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

<figure><img src="/files/NDpIRzTygli5Lgm8xAvj" alt="" width="188"><figcaption><p>Enum with enemies</p></figcaption></figure>

3. In a new row below the last entry, type your Enemy name in camel code, without using spaces.&#x20;

<mark style="color:red;">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.</mark>

<mark style="color:yellow;">The format should be like in the picture above - "EnemyName = Order number, ". Make sure that every entry has a unique number.</mark>&#x20;

4. After making desired changes, save the script.
5. Now, navigate to the Scriptable file located here:

<figure><img src="/files/IyZQlXFap6cOet0Gg7WK" alt="" width="288"><figcaption><p>Enemy Database</p></figcaption></figure>

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.&#x20;

<figure><img src="/files/D6agjMpXSCU2OAeekRPX" alt="" width="330"><figcaption><p>Enemies List in the database</p></figcaption></figure>

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

&#x20;<mark style="color:yellow;">If you don't have an image or don't want it at all, you can choose None in the Icon field.</mark>

7. 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.
   {% endstep %}

{% step %}

### Enemy Customization

Finally, to make the enemy behave how you like, its recommended to change its Settings in the prefab under Enemy Behavior component:

<figure><img src="/files/9ABbxgBm7REUruhU7N02" alt="" width="323"><figcaption></figcaption></figure>

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:&#x20;

<figure><img src="/files/xFntJc6mUXiXwskxnZAk" alt="" width="323"><figcaption><p>Custom enemy material</p></figcaption></figure>

There, you can change the parameters to fit your needs.

<mark style="color:yellow;">If you are not satisfied with this shader effect, you can assign a different material in the field above.</mark>
{% endstep %}

{% step %}

### 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 [Creating a new stage](/monster-survivors-documentation/stages/create-a-stage.md)
{% endstep %}
{% endstepper %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://october-studio.gitbook.io/monster-survivors-documentation/enemies/add-a-simple-enemy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
