Show which room you are in
Updated
Two Audio Zones, a library with rain on its windows and a workshop with a drum loop: their enter and exit events name the room in a HUD label and lower the hall music.
With your sound on, hold A for half a second to walk into the library, or D to walk into the workshop. Inside a room you hear only its own sound, and the label names it. The rain and the beat are short loops generated for this example.
Show which room you are in
#pragma lifecycle(startup)
const ROOM_NAMES = { 'Library Zone': 'Library', 'Workshop Zone': 'Workshop',};let label;let hallMusic;let inside = 0;
function startup() { label = findEntity('Room Name').getComponent(UILabelComponent); hallMusic = findEntity('Hall Music').getComponent(AudioComponent);
on('room', (event) => { const zone = findEntity(event.entityId); if (event.eventType === EventType.AudioZone.Enter) { inside += 1; label.setProps({ text: ROOM_NAMES[zone.name] ?? zone.name }); hallMusic.setVolume(0.15); } if (event.eventType === EventType.AudioZone.Exit) { inside -= 1; if (inside === 0) { label.setProps({ text: 'Main hall' }); hallMusic.setVolume(0.6); } } });}How it works
Section titled “How it works”The script is explained step by step in Show which room you are in.
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.
RoomTracker.xrproj