Scripting / Components
Projectile
A self-propelled prefab that travels in a straight line and applies damage on impact. Spawn and fire it with Shoot() from inside a ranged instruction's Execute(), or attach ShootSuscriber to a player or enemy to fire automatically on each instruction.
Inspector Fields
| Field | Type | Description |
|---|---|---|
speed | float | Travel speed in world units per second. Default: 4. |
damage | int | Hit points removed from the first Health component hit. Default: 1. |
shootSound | AudioClip | Played once when the projectile is fired. |
hitSound | AudioClip | Played when the projectile hits a target. |
Methods
| Method | Description |
|---|---|
Shoot(ExecutionContext context, Direction direction, | Instantiates a copy of the projectile prefab at position with rotation, mirrors the sprite scale to face the direction, and begins movement. Returns the new instance. |
Usage example
Shoot() is called by ShootSuscriber — the built-in IExecutionSuscriber that fires the projectile each time a character executes an instruction. The instruction itself keeps Execute() empty and handles only the animation in Tick():
// ShootSuscriber.Execute — called automatically via OnExecute public void Execute(ExecutionContext context) { projectile.Shoot(context, controller.direction, transform.position, transform.rotation); } // The instruction plays the animation — Execute() is empty protected override IEnumerator Tick(ExecutionContext context) { context.player.SetDirection(direction); context.player.PlayAnimation("Shoot"); yield return new WaitForSeconds(1.5f); }
Attach ShootSuscriber to the player or enemy root and assign the prefab. Both PlayerController and EnemyController auto-discover it during Initialize() — no manual wiring needed.
The built-in
ShootSuscriber IExecutionSuscriber wraps Shoot for use on players or enemies. Attach it to the character's root (or any child) and assign the prefab — both PlayerController and EnemyController auto-discover it. Use it when the character should fire a projectile on every instruction execution; for a specific shoot instruction call Shoot directly in Execute().