Radio buttons with a selection group
Updated
Three UI Checkboxes drawn as radio buttons and made exclusive by a UI Selection Group, which a Behavior script adds; the log reports the chosen difficulty.
Pick Easy, Normal or Hard: the others turn off and the log names your choice. Drag outside the panel to orbit the camera, scroll to zoom.
Radio buttons with a selection group
#pragma lifecycle(startup)
const NAMES = ['Easy', 'Normal', 'Hard'];let difficulty = 'Normal';
function startup() { for (const name of NAMES) { const entity = findEntity(name); entity.getComponent(UICheckboxComponent).setProps({ text: name, radio: true }); entity.addComponent(new UISelectionGroupComponent({ group: 'difficulty' })); } findEntity(difficulty).getComponent(UICheckboxComponent).setChecked(true);
on('settings/difficulty', (event) => { if (event.eventType !== EventType.UICheckbox.Change || !event.data.checked) return; difficulty = findEntity(event.entityId).name; log('difficulty is now', difficulty); });}How it works
Section titled “How it works”The script is explained step by step in Radio buttons with a selection group.
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.
DifficultyRadios.xrproj