Okay, so I have a code to change scenes with the press of a button and for some reason, it doesn’t work!
Here’s my code:
var Playbutton = pc.createScript('playbutton');
Playbutton.attributes.add("sceneId", {type: "string", default: "0", title: "Scene ID To Load"});
Playbutton.prototype.initialize = function() {
this.entity.element.on('mouseenter', this.onEnter, this);
this.entity.element.on('mousedown', this.onPress, this);
this.entity.element.on('mouseup', this.onRelease, this);
this.entity.element.on('mouseleave', this.onLeave, this);
};
Playbutton.prototype.onPress = function(event) {
var oldHierachy = this.app.root.findByName("Root");
oldHierachy.destroy();
this._loadSelectedScene();
};
Playbutton.prototype._loadSelectedScene = function () {
if (!this._loadingScene) {
this._loadingScene = true;
this._loadSceneButtonactive = false;
var self = this;
this.app.scenes.loadSceneHierarchy(scene.url, function (err, loadedSceneRootEntity) {
if (err) {
console.error(err);
} else {
loadedSceneRootEntity.reparent(this.sceneId);
self._loadingScene = false;
self._loadSceneButton.active = true;
}
});
}
};