Skip to content

Instantly share code, notes, and snippets.

@juanigallo
Created March 9, 2022 18:41
Show Gist options
  • Save juanigallo/ca1ada0c4435d09bc9a3c1f95ad8a568 to your computer and use it in GitHub Desktop.
Save juanigallo/ca1ada0c4435d09bc9a3c1f95ad8a568 to your computer and use it in GitHub Desktop.
import * as utils from "@dcl/ecs-scene-utils";
//Text
const nameEntity = new Entity();
const myName = new TextShape("@JuaniGallo");
nameEntity.addComponent(myName);
nameEntity.addComponent(new Transform({ position: new Vector3(8, 1, 8) }));
nameEntity.addComponent(
new utils.ToggleComponent(utils.ToggleState.Off, (value) => {
if (value == utils.ToggleState.On) {
nameEntity.addComponentOrReplace(
new utils.KeepRotatingComponent(Quaternion.Euler(0, 45, 0))
);
} else {
nameEntity.getComponent(utils.KeepRotatingComponent).stop();
}
})
);
//Button
const buttonEntity = new Entity();
buttonEntity.addComponent(new BoxShape());
buttonEntity.addComponent(
new Transform({ position: new Vector3(3, 1, 8), scale: new Vector3(2, 2, 2) })
);
buttonEntity.addComponent(
new OnPointerDown(() => {
nameEntity.getComponent(utils.ToggleComponent).toggle();
})
);
//Engine
engine.addEntity(nameEntity);
engine.addEntity(buttonEntity);
utils.addLabel("Clickeame", buttonEntity);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment