A menu on the screen gamepad
Updated
The camera’s Screen Gamepad shows a D-pad and an A button; a script moves through a menu on presses of 1 and 3 and chooses with A.
Press the 1 and 3 buttons of the on-screen pad to move through the menu.
A menu on the screen gamepad
#pragma lifecycle(startup)
const OPTIONS = ['Resume', 'Settings', 'Quit'];let index = 0;
function startup() { const label = findEntity('Menu Label').getComponent(UILabelComponent); const show = () => label.setProps({ text: `> ${OPTIONS[index]}` }); show();
on('pad', (event) => { if (event.eventType !== EventType.ScreenGamepad.Press) return; const button = event.data.button; if (button === '1') index = (index + OPTIONS.length - 1) % OPTIONS.length; // up if (button === '3') index = (index + 1) % OPTIONS.length; // down if (button === 'a') emit('menu/choose', { option: OPTIONS[index] }); show(); });}How it works
Section titled “How it works”The script is explained step by step in A menu on the screen gamepad.
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.
PadMenu.xrproj