Switch a projector between images
Updated
Clicking the button switches a projector between a day and a night pattern, zooming the night one and dimming the beam.
Click the blue button on the stand to switch between the day and night patterns. Drag elsewhere to orbit the camera, scroll to zoom.
Switch a projector between images
#pragma lifecycle(startup)
const DAY = { src: '/example-assets/lemon-decal.png', zoom: 1 };const NIGHT = { src: '/example-assets/alpha.png', zoom: 1.4 };
async function startup() { const lamp = findEntity('Window Light'); const projector = lamp.getComponent(SpotLightProjectorComponent); const beam = lamp.getComponent(SpotLightBeamComponent); let night = false;
projector.setProps(DAY); await projector.load();
on('projector/next', async (event) => { if (event.eventType !== EventType.Selectable.Select) return; findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again night = !night; projector.setProps(night ? NIGHT : DAY); beam.setProps({ opacity: night ? 0.08 : 0.2 }); await projector.load(); log(night ? 'Night pattern' : 'Day pattern'); });}How it works
Section titled “How it works”The script is explained step by step in Switch a projector between images.
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.
PatternSwitch.xrproj