Level logic: doors, buttons and triggers¶
Interactive objects live in Prefabs/Level and connect through UnityEvents — e.g. a lever's ButtonDown calls Door.OpenDoor.
The player interacts (E) with the object in the cell ahead, for free (no turn spent). Priority when several apply: Shop 500 > NPC 400 > Button 300 > Chest 200 > Door 100.
Add a door¶
Use Door (wood) or Door_Grate. Set triggerMode (Interaction = E, Automatic = opens when near, None = event only), keyType (None/Red/Blue/Yellow, recolors the door), startOpen and openOnce. Methods: OpenDoor(), CloseDoor(), ToggleDoor().
Doors are used along the passage, never from the side. Open state and keys (Prefabs/PickUp/Keys/*, valid for the current level only) are saved by checkpoints.
New style: make a Prefab Variant of Door and replace the face materials and keyMaterials (order None, Red, Blue, Yellow). The texture is a 160×160 atlas: faces in the bottom-left 128×128, sides and top in the 32 px strips.
Add a lever or button¶
Use SingleButton or a style variant (_Iron, _Stone, _Wood, ...). PressAndRelease fires ButtonDown, waits pressTime, then fires ButtonUp; PressOnly fires ButtonDown and stays down. useOnce is restored pressed from checkpoints without re-firing.
Placed against a wall at the cell edge, it becomes a wall lever: it doesn't block the floor and is used by facing the wall. At the cell center it is a pedestal.
Sample level ending
A PressOnly + useOnce lever calls Door.OpenDoor on a door with triggerMode = None and openOnce; the LevelExitPortal is behind it.
Add chests and secrets¶
Chestgives usable items straight to the inventory from a loot table (Data/PickUp/LootTables);dropChanceis 0–100. Opens once unlessrepeatable.- Add
Secretto an object and callSecret.FindSecret()from an event (hidden lever, trigger). It counts toward the medal.
Add a checkpoint¶
CheckPoint saves when the player enters its volume (once, unless repeatable). The player respawns at the checkpoint's cell, so you can stretch the trigger safely.
Warning
Conversations, shop usage, platforms and spikes are not saved. Everything else that matters (health, inventory, keys, kills, pickups, doors, buttons, triggers, secrets, explored area, time) is.
Add a trigger¶
Triggers derive from BaseLevelTrigger (useOnce, activationDelayTurns; 0 = immediate). Prefabs: Trigger, TriggerAmbush.
EnemyActivateTriggeractivates listed enemies (or all) and fires UnityEvents.EnemyAmbushTriggerruns wave ambushes — see Ambushes and bosses.MusicZonechanges music while the player is inside.
Detection uses the player position inside the collider bounds, not physics events.
using AiasTech.Level;
using UnityEngine;
public sealed class ToggleDoorTrigger : BaseLevelTrigger
{
[SerializeField] private Door door;
protected override void OnActivated() => door?.OpenDoor();
protected override void OnDeactivated() => door?.CloseDoor();
}
Warning
On checkpoint load, a fired trigger calls OnRestoredAsFired(), which calls OnActivated() again by default. Make callbacks safe to run twice, or override it.
Add traps, areas and platforms¶
AutoSpikerises and falls with turns (turnsToFullyExtend,bottomRestTurns); raised, it damages and pushes the player back.AreaEffect_Lavadamages andAreaEffect_Healheals (forhealTurnsturns) on entry and each turn inside.Barrelexplodes with area damage (radius in cells). Area damage scales with difficulty.Platformcarries the player between waypoints at cell centers, along grid rows or columns; input is locked during the ride. Its Inspector builds and validates the route.
Add NPCs¶
Prefabs/NPC/TalkingNpc plays a list of DialogueLines (localization key or fallback text); ShopNpc opens the shop. repeatable controls reuse. For wandering, enable wander on GridNpcController. NPC scenes need UILevel and AiasEventSystem.
Extend with code¶
- Interactable: derive from
GridInteractable, returntrueonly if something happened, callbaseinOnEnable/OnDisable, and callGridInteraction.NotifyPromptsChanged()if the prompt changes on its own. - Checkpointed object: add
[SerializeField] string mapId, implementIPersistentSceneObject, callSceneObjectId.EnsureId(this, ref mapId)inOnValidate(inside#if UNITY_EDITOR), and save/restore throughLevelWorldTracker. UseChestandDestructibleObjectas models.