A small Unity 6 starter project for practicing first-person raycast interaction architecture.
The scene is intentionally compact: the player finds a keycard, unlocks a door, presses a button to disable a laser trap, and reaches an exit trigger. The focus is clean object communication, not visual production.
Author: Justin Tolstoy tolstoyjustin@gmail.com
- Unity version:
6000.4.10f1 - Render pipeline: Universal Render Pipeline
- Input: Unity Input System
- Main scene:
Assets/Scenes/SampleScene.unity
- Move:
WASDor arrow keys - Look: mouse
- Interact:
E - Unlock mouse:
Esc - Restart after escape:
Ror clickPlay Again
- Read the hint note.
- Pick up the keycard.
- Press the button to disable the laser trap.
- Use the keycard on the locked door.
- Walk into the exit zone.
- Restart from the end screen if needed.
The project keeps interaction logic separated into small scripts:
IInteractable.csdefines the shared interaction contract.PlayerInteractor.csraycasts from the player camera and callsInteract.Keycard.csupdates inventory state throughGameManager.Door.cschecks game state and opens itself.ButtonSwitch.cschanges scene state by disabling the trap.Trap.csresets the player when active.EscapeZone.csvalidates the win condition.GameManager.csstores shared state and handles reset/replay flow.UIManager.csowns prompts, messages, inventory text, and end options.
This makes it easy to add another interactable object without changing the player interaction script.
The project includes two helper menu actions:
Tools/Escape Room/Rebuild Room LayoutTools/Escape Room/Install Gameplay
Use these only if you want to regenerate the simple challenge scene. The committed SampleScene is already set up.
How does the player detect interactable objects?
PlayerInteractor casts a ray from the player camera each frame. If the ray hits a component implementing IInteractable, the UI prompt appears and pressing E calls Interact.
Why is an IInteractable interface useful?
It lets the player talk to any interactable object through one common contract. A keycard, door, button, or note can all be added without rewriting the player script.
Where is hasKeycard stored?
Inventory state is stored centrally in GameManager as HasKeycard.
Does the door know about the player directly?
No. The door checks shared game state through GameManager, so it does not need a direct player reference.
Could a new interactable be added quickly?
Yes. Add a component that implements IInteractable, return a prompt string, and implement its Interact behavior.
This repo commits Unity source files only. Generated folders such as Library, Temp, Logs, and UserSettings are intentionally ignored.