Lock the door once a puzzle is solved
Updated
When the puzzle is solved, a script snaps a door shut and locks every axis of its Handle; resetting the puzzle restores the Handle’s props.
Drag the door to swing it, then press Solve puzzle: it snaps shut and no longer moves. Press Reset puzzle to unlock it. Scroll to zoom.
Lock the door once a puzzle is solved
#pragma lifecycle(startup)
function startup() { const hinge = findEntity('Door Hinge'); const handle = hinge.getComponent(HandleComponent);
on('puzzle/solved', () => { // Snap the door shut, then lock every axis. hinge.setRotation(0, 0, 0); handle.setProps({ translate: false, rotate: false, scale: false }); log('The door is locked'); });
on('puzzle/reset', () => { handle.setProps({ translate: 'as-rotate', rotate: { x: false, y: [-Math.PI / 2, 0], z: false } }); });}How it works
Section titled “How it works”The script is explained step by step in Lock the door once a puzzle is solved.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
LockOnSolve.xrproj