Cycle through security cameras with a key
Updated
Three named cameras watch a small town: each press of Tab cuts to the next feed with CameraDirector.switchTo, and after the last one, or on Escape, back to the main camera.
Click the scene, then press Tab to step through the lobby, vault and roof cameras; press Escape to return to your own view.
Cycle through security cameras with a key
#pragma lifecycle(update)
const FEEDS = ['Lobby Cam', 'Vault Cam', 'Roof Cam'];let index = -1; // -1 means the player's own view
function update() { if (Input.keyboard.isKeyReleased(Key.Tab)) { index = index + 1 >= FEEDS.length ? -1 : index + 1; if (index === -1) CameraDirector.switchToMain(); else CameraDirector.switchTo(FEEDS[index]); log('Now viewing', CameraDirector.current?.name ?? 'default camera'); } if (Input.keyboard.isKeyReleased(Key.Escape) && index !== -1) { index = -1; CameraDirector.switchToMain(); }}How it works
Section titled “How it works”The script is explained step by step in Cycle through security cameras with a key.
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.
SecurityMonitor.xrproj