Hi, i had a problem while trying to make an “exit” button here is the code that i wrote any help pls!
var Exit = pc.createScript('exit');
// initialize code called once per entity
Exit.prototype.initialize = function() {
this.entity.button.on('click', function(event) {
// Find the Scene Registry Item by the name of the scene
var sceneItem = this.app.scenes.find('Menu');
// Load the scene data with a callback when it has finished
this.app.scenes.loadSceneData(sceneItem, function (err, sceneItem) {
if (err) {
console.error(err);
} else {
// Destroy all children under application root to remove the current loaded scene hierarchy
var rootChildren = this.app.root.children;
while(rootChildren.length > 0) {
rootChildren[0].destroy();
}
// loadSceneHierarchy and loadSceneSettings is now a synchronous function call as
// the the scene data has been loaded
this.app.scenes.loadSceneHierarchy(sceneItem);
this.app.scenes.loadSceneSettings(sceneItem);
// Optional: unload the scene data to free resources
this.app.scenes.unloadSceneData(sceneItem);
}
}.bind(this));
}, this);
};