Skip to content

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

  • Chest gives usable items straight to the inventory from a loot table (Data/PickUp/LootTables); dropChance is 0–100. Opens once unless repeatable.
  • Add Secret to an object and call Secret.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.

  • EnemyActivateTrigger activates listed enemies (or all) and fires UnityEvents.
  • EnemyAmbushTrigger runs wave ambushes — see Ambushes and bosses.
  • MusicZone changes 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

  • AutoSpike rises and falls with turns (turnsToFullyExtend, bottomRestTurns); raised, it damages and pushes the player back.
  • AreaEffect_Lava damages and AreaEffect_Heal heals (for healTurns turns) on entry and each turn inside.
  • Barrel explodes with area damage (radius in cells). Area damage scales with difficulty.
  • Platform carries 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, return true only if something happened, call base in OnEnable/OnDisable, and call GridInteraction.NotifyPromptsChanged() if the prompt changes on its own.
  • Checkpointed object: add [SerializeField] string mapId, implement IPersistentSceneObject, call SceneObjectId.EnsureId(this, ref mapId) in OnValidate (inside #if UNITY_EDITOR), and save/restore through LevelWorldTracker. Use Chest and DestructibleObject as models.