Skip to content

Instantly share code, notes, and snippets.

@cj

cj/test.js Secret

Created June 28, 2022 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cj/8b41f342d44cdae0d720e8ab5077af71 to your computer and use it in GitHub Desktop.
Save cj/8b41f342d44cdae0d720e8ab5077af71 to your computer and use it in GitHub Desktop.
/* jshint esversion: 6 */
var Test = pc.createScript('test');
var Text = 90782882;
var Letter;
var START_POSITION = new pc.Vec3(0, 5, 0);
// initialize code called once per entity
Test.prototype.initialize = function () {
this._createLetter();
};
// update code called every frame
Test.prototype.update = function (dt) {
};
// swap method called for script hot-reloading
// inherit your script state here
Test.prototype.swap = function (old) {
Letter.destroy();
this._createLetter();
};
// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/
// PRIVATE FUNCTIONS
Test.prototype._createLetter = function () {
const templateAsset = this.app.assets.get(Text);
Letter = templateAsset.resource.instantiate();
// this.app.root.addChild(instance);
// const templates = this.app.root.findByName('Templates');
// const Text = templates.findByName('Text');
// const Letter = Text.clone();
Letter.setPosition(START_POSITION);
Letter.script.textMesh.text = 'Hello World!';
// Letter.name = "Hello World";
Letter.addComponent("collision", {
type: 'mesh',
asset: Letter,
// halfExtends: new pc.Vec3(1, 1, 1)
});
Letter.addComponent("rigidbody", {
type: pc.BODYTYPE_DYNAMIC,
});
console.log(Letter);
this.app.root.addChild(Letter);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment