face-smile-plusHow to add a new Enemy

This guide explains how to add a new enemy to the game. As an example, we’ll create and configure a completely new enemy from scratch - including assets, animations, behavior, and data setup.

1. Importing Assets

  • Inside Assets/The Archer/Models/Enemies, create a new folder named after your enemy. Import the 3D model and animation clips there.

  • Inside Assets/The Archer/Textures/Enemies, import your enemy’s texture.

You’ll need the following assets for your enemy:

  • 3D Model

  • Animations

  • Texture

Folder Setup

  1. In Assets/The Archer/Enemies, create a new folder named after your enemy. Import your 3D model and animation clips there.

  2. In Assets/The Archer/Textures/Enemies, import your enemy’s texture.

2. Configuring Animator and Animations

Enemy animator setup is more flexible than the hero’s - it depends heavily on the specific behavior of your enemy. The template already includes a wide variety of enemies, which you can use as references.

Animation Configuration

  1. Ensure each animation clip is properly configured (looped if needed).

  2. Add commonly used animation events such as:

    • OnDefeatAnimationEnded

    • OnAttack

    • OnAttackEnded

  3. Clone an existing animator or create a new one and place it in the same folder as the 3D model.

Required Animator Parameters

The abstract class EnemyBehavior expects the following animator parameters:

Parameter
Type
Description

Movement Blend (EnemyBehavior.MOVEMENT_BLEND_FLOAT)

Float

Controls movement blend tree (idle, walk, run). Skip if your enemy doesn’t move.

Defeat (EnemyBehavior.DEFEAT_TRIGGER)

Trigger

Plays the defeat animation.

Hit

(EnemyBehavior.HIT_TRIGGER)

Trigger

Plays the hit reaction animation.

Attack (EnemyBehavior.ATTACK_TRIGGER)

Trigger

Plays the attack animation.

Attack Ended (EnemyBehavior.ATTACK_ENDED_TRIGGER)

Trigger

Ends a looping attack animation.

Hide

(EnemyBehavior.HIDE_TRIGGER)

Trigger

Plays a hide animation (used, for example, by enemies that burrow).

Show

(EnemyBehavior.SHOW_TRIGGER)

Trigger

Plays a show animation (usually paired with Hide).

Attack Type (EnemyBehavior.ATTACK_TYPE_INT)

Int

Defines which attack animation to play when the enemy has multiple attacks.

Enemy animators typically have at least two layers:

  • Base Layer - main animations (idle, movement, attack).

  • Hit Layer - hit reactions, allowing the enemy to play “hit” animations without interrupting other actions.

3. Creating Enemy Behavior

  1. Navigate to:

    • Assets/The Archer/Scripts/Enemies/Simple Enemies (for regular enemies), or

    • Assets/The Archer/Scripts/Enemies/Bosses (for boss enemies).

  2. Create a new folder named after your enemy.

  3. Inside it, create a new script named [Name]EnemyBehavior.cs.

Base Setup

Open the script and inherit from EnemyBehavior. Override the BehaviorCoroutine method - this is the main loop that defines the enemy’s logic:

Use existing enemies as examples to learn about structure and pacing.

Typical Attack Example

waitForAttackToEnd is an instance of a custom WaitUntilTrue class, which blocks coroutine execution until its Complete() method is called.

Usually, the attack animation triggers OnAttackEnded at the end - this signals the coroutine to continue. If your attack involves projectiles, add an animation event to call the projectile-spawn logic at the right frame.

Animation Events Handling

The EnemyEventsHandler component is responsible for catching animation events and forwarding them to the enemy script. By default, it provides the following callbacks:

Animation Event
Calls Enemy Method

OnDefeatAnimationEnded

OnDefeatEndedEventFired()

OnAttack

OnAttackEventFired()

OnAttackEnded

OnAttackEndedEventFired()

OnHidden

OnHideEndedEventFired()

OnSpawnEnded

OnSpawnEndedEventFired()

If your enemy requires additional events, create a new class that inherits from EnemyEventsHandler and extend it with your custom event logic.

4. Creating Enemy Prefab

  1. Navigate to:

    • Assets/The Archer/Prefabs/Enemies/Simple Enemies (for regular enemies), or

    • Assets/The Archer/Prefabs/Enemies/Bosses (for bosses).

  2. Clone an existing enemy prefab and rename it to your enemy’s name.

  3. Remove the old model and all components except the Healthbar and Helpers GameObject (with its children).

What to remove
  1. Drag your new enemy model into the prefab.

  2. Assign your Animator Controller to the Animator component.

  3. Add the EnemyEventsHandler component (or your custom subclass if you extended it).

Renderers Helper Setup

  1. Select the Renderers Helper GameObject.

  2. Add all your model’s Mesh Renderers to its Renderers list.

  3. Remove any unassigned elements.

Enemy Behavior Setup

  1. Select the Root GameObject.

  2. Without removing the existing EnemyBehavior, add your new Enemy Behavior component.

  3. Copy all commonly used field values from the old component to your new one, then delete the old one.

  4. Assign:

    • Animator

    • Graphic Object (the model’s root GameObject)

  5. Adjust any custom parameters controlling your enemy’s behavior.

  6. Resize the collider and adjust the healthbar height to fit your model.

5. Assigning Enemy Data

  1. Open: Assets/The Archer/Scriptables/Enemies Database

  2. Add a new entry to the Enemies List and fill in:

    • Enemy Name

    • Prefab

    • Sprite

    • Is Boss

    • Item Drops (and the player HP percentages at which they drop)

  3. Press the button next to the Enemy Type value.

  1. In the window that opens, click Add.

  2. Enter your enemy’s name and assign a unique index.

  3. Press Save.

That’s it! Your new enemy should now appear in the Stage Creator. Add it to any wave and start the game — it should spawn and behave according to your configuration.

Last updated