Scripting / Components
PlayerController
Root MonoBehaviour for the player prefab. Extends CharacterInstanceController with inventory-driven damage and defense stats, stamina, item usage visual effects, audio playback, and tile position validation. Initialized automatically by the InstructionRunner at level start — requires an ActiveEffectsController on the same GameObject.
Inspector Fields
| Field | Type | Description |
|---|---|---|
damageStat | Stat | Stat asset used to look up the player's damage value from the inventory. |
defenseStat | Stat | Stat asset used to look up the player's defense value from the inventory. |
useItemFX | ItemUsedFX | Prefab spawned to display a floating item icon when an item is used. See ItemUsedFX. |
useItemParticles | ParticleSystem | Particle system played at the player's position during item use. |
Properties
| Property | Type | Description |
|---|---|---|
stamina | PlayerStamina | The PlayerStamina component on this character. Retrieved on Awake. |
damage | int | Damage value read from PlayerInventory using damageStat. Overrides the base class virtual property. |
defense | int | Defense value read from PlayerInventory using defenseStat. Overrides the base class virtual property. |
Events
| Event | Signature | Description |
|---|---|---|
OnExecute | Action<ExecutionContext> | Fired each time the player executes an instruction. All IExecutionSuscriber components found in the hierarchy during Initialize() subscribe to this automatically. |
Methods
| Method | Description |
|---|---|
Initialize(ExecutionContext context, | Sets up the inventory reference, retrieves stamina, and subscribes all IExecutionSuscriber children to OnExecute. Called automatically at level start by the InstructionRunner. |
ValidatePosition() → bool | Returns true if the player's current tile is a PathTile and is not occupied by an IObstacle. |
ValidatePosition(Vector3 position) → bool | Overload that validates an arbitrary world position instead of the player's current one. |
UseItem(Item item) | Spawns the useItemFX prefab at the player's position, plays useItemParticles, then applies the item's effects to all IStatEffectReceiver components on the hierarchy. |
PlaySound(AudioResource resource) | Stops any currently playing sound and plays the given AudioResource on the character's AudioSource. |
Inherited from CharacterInstanceController
The following members are defined on the base class and available on every PlayerController instance:
| Member | Type | Description |
|---|---|---|
position | Vector2 (get/set) | World-space position of the character. Writing this moves the character instantly. |
direction | Direction | Current facing direction. |
health | Health | The Health component managing hit points and death. |
blocking | bool | Whether the character is currently in a blocking pose. Checked by PlayerHealth 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. |
Access
PlayerController from inside any instruction via context.player. See ExecutionContext for the full player API surface.