A remote with a page indicator
Updated
Two UI buttons turn the pages of a PDF handout and a label shows “Page 2 of 3”, kept right by the document’s own ready and page events: a PDF, a Text and a Behavior script.
Press Next and Previous, or use the pill under the document. Drag to orbit the camera, scroll to zoom.
A remote with a page indicator
#pragma lifecycle(startup)
let handout;let label;let pages = 1;
function showPage(page) { label.setProps({ text: `Page ${page} of ${pages}` });}
function startup() { handout = findEntity('Handout').getComponent(PDFComponent); label = findEntity('Page Label').getComponent(TextComponent); label.setProps({ text: 'Loading…' });
on('handout', (event) => { if (event.eventType === EventType.PDF.Ready) { pages = event.data.pages; showPage(handout.props.page); } if (event.eventType === EventType.PDF.Page) { pages = event.data.pages; showPage(event.data.page); } if (event.eventType === EventType.PDF.Error) { label.setProps({ text: 'Document unavailable' }); } });
on('handout/next', (event) => { if (event.eventType !== EventType.UIButton.Press) return; const page = handout.props.page; handout.setProps({ page: page < pages ? page + 1 : 1 }); });
on('handout/prev', (event) => { if (event.eventType !== EventType.UIButton.Press) return; const page = handout.props.page; handout.setProps({ page: page > 1 ? page - 1 : pages }); });}How it works
Section titled “How it works”The script is explained step by step in A remote with a page indicator.
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.
PdfRemote.xrproj