Open a door by name
Updated
A script finds the entity named Door once, then swings it open with setRotation when O is pressed and shut when C is pressed.
Click the scene, then press O to open the door and C to close it. Drag to orbit the camera, scroll to zoom.
Open a door by name
#pragma lifecycle(startup, update)
let door = null;let open = false;
function startup() { door = findEntity('Door'); if (!door) log('No entity named Door in', scene.name);}
function update() { if (!door) return; if (!open && Input.keyboard.isKeyReleased(Key.O)) { open = true; door.setRotation(0, DEG_TO_RAD(90), 0); log(door.name, 'opened'); } if (open && Input.keyboard.isKeyReleased(Key.C)) { open = false; door.setRotation(0, 0, 0); log(door.name, 'closed'); }}How it works
Section titled “How it works”The script is explained step by step in Open a door by name.
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.
DoorOpener.xrproj