A click sound for any button
Updated
Every button of a menu plays the same short click, rewound on each press so fast presses all sound: one Audio entity with autoplay off, played by a Behavior script on a shared signal.
Press the buttons, quickly too. Drag to orbit the camera, scroll to zoom. The click is a tiny sound generated for this example.
A click sound for any button
#pragma lifecycle(startup)
let click;
function startup() { click = findEntity('Click').getComponent(AudioComponent);
on('ui/press', (event) => { if (event.eventType !== EventType.UIButton.Press) return; click.stop(); // rewind, in case the last click is still playing click.play(); });}How it works
Section titled “How it works”The script is explained step by step in A click sound for any button.
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.
ButtonClickSound.xrproj