Hello cube
Updated
A box that spins every frame and takes a new colour when you click it: a Behavior script, a Selectable and a Signal Emitter.
Click the box. Drag to orbit the camera, scroll to zoom.
Hello cube
#pragma lifecycle(startup, update)
const SPIN = 0.5; // radians a secondlet box;
function startup() { box = self.parent; on('box/clicked', (event) => { if (event.eventType !== EventType.Selectable.Select) return; // Select fires only on becoming selected: release it so every click counts. box.getComponent(SelectableComponent).setSelected(false); box.getComponent(StandardMaterialComponent).setProps({ color: `#${Random.color().getHexString()}` }); log('Box clicked'); });}
function update(dt) { box.rotation.y += dt * SPIN;}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.
HelloCube.xrprojWhat it uses
Section titled “What it uses”- Geometry
- Standard Material
- Selectable
- Signal Emitter
- Behavior
- Camera Perspective
- Main Camera
- Orbit Controller