Weather that fades in and out
Updated
Rain and wind ambiences with an Audio Fade each: a Behavior script only enables and disables the two Audio entities, and the fades cross over two seconds.
With your sound on, press Rain: the wind fades out as the rain fades in over two seconds. Press Clear to swap back. The rain is a short loop generated for this example. Drag outside the panel to orbit the camera.
Weather that fades in and out
#pragma lifecycle(startup, update)
let rain;let wind;let drops;let forecast;
function setWeather(kind) { const raining = kind === 'rain'; rain.setEnabled(raining); // fades in over 2 s when enabled wind.setEnabled(!raining); // fades out over 2 s when disabled drops.setEnabled(raining); forecast.setProps({ text: raining ? 'Rain: the rain fades in, the wind fades out' : 'Clear: the wind fades in, the rain fades out' }); log('weather:', kind);}
function startup() { rain = findEntity('Rain'); wind = findEntity('Wind'); drops = findEntity('Rain Drops'); forecast = findEntity('Forecast').getComponent(UILabelComponent);
on('weather/rain', () => setWeather('rain')); on('weather/clear', () => setWeather('clear'));}
function update(dt) { if (!drops.isEnabled()) return; for (const drop of drops.children) { drop.position.y -= dt * 4; if (drop.position.y < -2.6) drop.position.y += 2.6; }}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.
WeatherFade.xrproj