A keypad that opens a vault
Updated
A numeric UI Keyboard placed in the scene types into a number field; a Behavior script checks the code on submit and swings the vault door open with a tween.
Click the code field, then press 2, 4, 6, 8 and the enter key on the in-scene keypad. A wrong code clears the field. Drag outside the panel to orbit the camera, scroll to zoom.
A keypad that opens a vault
#pragma lifecycle(startup)
const CODE = '2468';let status;let door;let open = false;
function startup() { const code = findEntity('Code').getComponent(UIInputComponent); status = findEntity('Status').getComponent(UILabelComponent); door = findEntity('Vault Door'); const keypad = findEntity('Keypad').getComponent(UIKeyboardComponent); log('keypad shown:', keypad.isShown());
// Every keyboard reports its keys on 'ui:keyboard'. on('ui:keyboard', (event) => { if (event.eventType === EventType.UIKeyboard.Press) log('key', event.data.key); });
on('vault:code', (event) => { if (event.eventType !== EventType.UIInput.Submit || open) return; if (event.data.text === CODE) { open = true; status.setProps({ text: 'Unlocked. Welcome in!', color: '#34d399' }); Tween.to(door.rotation, { y: -1.9 }, { duration: 1.2 }); } else { status.setProps({ text: 'Wrong code, try again.', color: '#f87171' }); code.setValue(''); } });}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.
VaultKeypad.xrproj