đ°Getting Started | â**Updates |** đ Guides | đ˘ API | âFAQ
Web Editor Basics
HoloLens
Mobile
Meta Quest
Chapter Series Documentation
Assets
Scripting
Enklu Embedded
API Reference
Release Notes
FAQ
Contact
To create a Button in your experience that can be pressed to make something happen in your experience, simply press the three dots dropdown in the hierarchy and select the âButtonâ option.
An element labelled âButtonâ will show up, and a spherical object will appear in the scene. In the Web Editor, you can click it with the left mouse button to see what happens when the button is activated. However, the button wonât do anything on its own - you will need to interact with the Button API.
Below is some example code. If this element was created from the âButtonâ option, its self
will contain a button
object that enables you to assign something to happen when the button is pressed and change the buttonâs visual appearance.
See this page for lists of fonts, colors, icons and other values that you can use here.
// includes
const messages = require('messages');
const self = this;
const button = self.button;
// public fields
const LABEL = '{[Label:string]}';
const COLOR = '{[Color:string]}';
const ICON = '{[Icon:string]}';
const FONT_SIZE = {[Font Size:int=80]};
const DISPLAY = "{[Display Mode:string=Occluded]}";
/**
* Called when the script is initialized.
*/
function enter() {
button.label = LABEL;
button.color = COLOR;
button.icon = ICON;
button.fontSize = FONT_SIZE;
button.display = DISPLAY;
button.registerPress(onButtonPressed);
}
function onButtonPressed() {
log.info("the button was pressed!");
}
function exit() {
button.unregisterPress();
}
You now have a pressable button that invokes JavaScript code! The best way to make it trigger other events in the experience is to make it dispatch a message on press. See the Messages API.
You will always be able to tell if a scene element is a Button Element if you see this label at the top of its inspector:
If you mark a Button Element as âNetworkedâ, if it is pressed while connected to a multiplayer game, the code will be invoked on the Host device rather than on the clientâs device. This makes it possible for individual players to affect whatâs going on in the central game running on the server.
Search for the relevant property here to see all available options.
button.label = "Hello World!";
button.fontSize = 80;
button.display = "Occluded";
button.lineSpacing = 0.5;
button.color = "Highlight";
button.icon = "play";
button.registerPress(function);
button.unregisterPress();
Sidebar Table of Contents
Copyright Š 2021 Enklu, Inc.