Tap to place on a phone
Updated
On an AR phone, a tap on the floor drops an anchored copy of a hidden plant there: XRRaycaster.fromScreen finds the surface, spawn copies the plant and anchorAt ties it to the spot.
This one needs AR: open the page on an AR phone. On a desktop there is no real surface to hit, so nothing is placed.
Tap to place on a phone
#pragma lifecycle(startup, update)
let screen;let lastHit = null;
function startup() { screen = Input.xr.controller(0);}
function update() { const hit = XRRaycaster.fromScreen().hit({ maxDistance: 5 }); if (hit) lastHit = hit;
if (!screen.isReleased(XRButton.Trigger) || !lastHit) return; const plant = spawn('Plant', { position: lastHit.point, enabled: true }); plant.getComponent(XRAnchorComponent).anchorAt(lastHit); lastHit = null;}How it works
Section titled “How it works”The script is explained step by step in Tap to place on a phone.
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.
TapToPlace.xrproj