Fade a light in and out
Updated
A script under a spot light tweens its intensity down to 0 and back up to 3, two seconds each way, for as long as it runs.
Watch the spot fade out and back in. Drag to orbit the camera, scroll to zoom.
Fade a light in and out
#pragma lifecycle(startup)
let light;let fade = null;
function fadeTo(target, seconds) { if (fade) fade.stop(); // a new fade replaces the old one fade = Tween.value(light.props.intensity, target, (value) => { light.setProps({ intensity: value }); }, { duration: seconds, ease: Ease.InOutSine }); return fade;}
async function startup() { // This Behavior entity is a child of the light. light = self.parent.getComponent(SpotLightComponent);
for (;;) { if (!(await fadeTo(0, 2))) return; // fade out over 2 s if (!(await fadeTo(3, 2))) return; // and back in }}How it works
Section titled “How it works”The script is explained step by step in Fade a light in and out.
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.
FadeLight.xrproj