Scripting / Components
EnemyController
Root MonoBehaviour for enemy prefabs. Extends CharacterInstanceController with patrol routing, player detection, attack-sequence cycling, and hover-highlight of attack range tiles. Implements IObstacle to block player movement and ITaskReceiver so the InstructionRunner can schedule its turn each loop iteration.
EnemyActionInstance
Serializable nested class used to populate the attackSequence array in the Inspector. Each slot pairs an EnemyAction with the number of loop iterations it runs for before the sequence advances.
| Field | Type | Description |
|---|---|---|
action | EnemyAction | The EnemyAction ScriptableObject to execute in this slot. |
loop | int | Number of loop iterations this action runs before the sequence moves to the next slot. |
Inspector Fields
| Field | Type | Description |
|---|---|---|
_damage | int | Base damage dealt per attack hit. |
_defense | int | Base defense value subtracted from incoming damage. |
defaultDirection | Direction | Facing direction applied when the level starts. |
loop | bool | When enabled the patrol sequence repeats from the beginning after reaching the last waypoint. |
moveSequence | Direction[] | Ordered patrol directions the enemy follows when no player is detected within range. |
directions | Direction[] | Directions to scan for the player each turn. |
range | int | Cell distance used when scanning for the player. |
attackSequence | EnemyActionInstance[] | Ordered attack actions with per-slot loop counts. Played in order when the player is detected. |
Properties
| Property | Type | Description |
|---|---|---|
damage | int (get/set) | Base damage dealt per attack. Overrides the base class virtual property. |
defense | int (get/set) | Defense value subtracted from incoming damage. Overrides the base class virtual property. |
currentInstruction | Instruction | The instruction currently being executed by this enemy. |
Events
| Event | Signature | Description |
|---|---|---|
OnMouseHover | Action<bool> | Fired on pointer enter (true) and pointer exit (false). Used by the Enemy HUD to show or hide the action panel. |
OnStart | Action | Fired when the attack sequence begins for the first time. |
OnActionChange | Action<EnemyAction> | Fired each time the active action changes within the attack sequence, passing the new action. |
OnEnd | Action | Fired when the full attack sequence has finished all of its iterations. |
OnExecute | Action<ExecutionContext> | Fired each time an instruction step executes. IExecutionSuscriber components are subscribed automatically during Initialize(). |
Methods
| Method | Description |
|---|---|
Initialize(ExecutionContext context, | Flattens the attackSequence into a per-instruction list, subscribes all IExecutionSuscriber children to OnExecute, and registers an OnDie callback to interrupt the current task when the enemy dies. |
GetTask() → Task | ITaskReceiver implementation. Scans the configured directions for the player — returns an attack Task if detected, a patrol Task otherwise. Called by the InstructionRunner each turn. |
Execute() | Runs the current instruction and fires OnExecute. Called by the active task once per turn step. |
PlaySound(AudioResource resource) | Stops any currently playing sound and plays the given AudioResource on the character's AudioSource. |
Validate() → bool | IObstacle implementation — always returns false, making the enemy an impassable obstacle that blocks player movement. |
Inherited from CharacterInstanceController
The following members are defined on the base class and available on every EnemyController instance:
| Member | Type | Description |
|---|---|---|
position | Vector2 (get/set) | World-space position of the character. |
direction | Direction | Current facing direction. |
health | Health | The Health component managing hit points and death. |
blocking | bool | Whether the enemy is in a blocking pose. Checked by EnemyHealth before applying damage. |
HUD | Transform | Root of the in-world HUD elements. Flipped alongside the sprite on direction changes. |
SetDirection(Direction direction) | — | Faces the character and flips the sprite and HUD for left/right directions. |
PlayAnimation(string stageName) | — | Plays an animator state by name. Does nothing if the character is dead. |
Enemies are fully autonomous. Place the prefab in the scene, configure
moveSequence and attackSequence in the Inspector, and the InstructionRunner schedules their tasks automatically each loop iteration — no scripting required for basic enemies.