A settings panel
Updated
A settings panel whose volume slider, mute switch and reset button drive the music: UI Slider, UI Switch and UI Button events handled by one Behavior script that sets an Audio volume.
With your sound on, move the slider, flip Mute and press Reset. Drag outside the panel to orbit the camera, scroll to zoom. The music is a short loop generated for this example.
A settings panel
#pragma lifecycle(startup)
function startup() { const music = findEntity('Music').getComponent(AudioComponent); const slider = findEntity('Volume').getComponent(UISliderComponent); const mute = findEntity('Mute').getComponent(UISwitchComponent);
slider.setProps({ text: 'Volume', min: 0, max: 100, step: 5, unit: '%' }); slider.setValue(80);
function apply() { music.setVolume(mute.isChecked() ? 0 : slider.getValue() / 100); }
on('settings:volume', (event) => { if (event.eventType === EventType.UISlider.Change) apply(); }); on('settings:mute', (event) => { if (event.eventType === EventType.UISwitch.Change) apply(); }); on('settings:reset', (event) => { if (event.eventType !== EventType.UIButton.Press) return; mute.setChecked(false); slider.setValue(80); });}How it works
Section titled “How it works”The script is explained step by step in A settings panel.
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.
UiSettingsPanel.xrproj