Drill holes at run time
Updated
Each press of H spawns a copy of a disabled cylinder tool, with a CSG set to subtract, under a panel at a random spot: every copy drills a new hole.
Click the scene, then press H to drill a hole; the panel takes up to twelve. Drag to orbit the camera, scroll to zoom.
Drill holes at run time
#pragma slot(ref=maxHoles, type=Integer, min=1, max=50, default=12)#pragma lifecycle(startup, update)
let panel;let drill;let holes = 0;
function startup() { panel = findEntity('Panel'); drill = findEntity('Drill');}
function update() { if (!Input.keyboard.isKeyReleased(Key.H)) return; if (holes >= maxHoles) { log('The panel cannot take more holes'); return; }
spawn(drill, { parent: panel, position: { x: Random.range(-0.8, 0.8), y: Random.range(-0.8, 0.8), z: 0 }, rotation: { x: M_HALF_PI, y: 0, z: 0 }, enabled: true, }); holes++;}How it works
Section titled “How it works”The script is explained step by step in Drill holes at run time.
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.
CsgDriller.xrproj