[SOLVED] Changing from scene to another

I have a project, where the first scene is the start of the game with 2 buttons, one of them when clicking on should direct me to the start of the game scene. I am trying to destroy the first scene so that the buttons disappear from the second scene I am directed to. Can someone help please.

The script I have found below:

var BtnStates = pc.createScript('btnStates'); BtnStates.attributes.add('hoverAsset', {
type:'asset',
assetType:'texture'
}); BtnStates.attributes.add('activeAsset', {
type:'asset',
assetType:'texture'
}); // initialize code called once per entity
BtnStates.prototype.initialize = function() {
// Get the original button texture
this.originalTexture = this.entity.element.textureAsset; // Whether the element is currently hovered or not
this.hovered = false; // mouse events
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); // touch events
this.entity.element.on('touchstart', this.onPress, this);
this.entity.element.on('touchend', this.onRelease, this);
}; // When the cursor enters the element assign the hovered texture
BtnStates.prototype.onEnter = function (event) {
this.hovered = true;
event.element.textureAsset = this.hoverAsset; // set our cursor to a pointer
document.body.style.cursor = 'pointer';
}; // When the cursor leaves the element assign the original texture
BtnStates.prototype.onLeave = function (event) {
this.hovered = false;
event.element.textureAsset = this.originalTexture; // go back to default cursor
document.body.style.cursor = 'default';
}; // When we press the element assign the active texture
BtnStates.prototype.onPress = function (event) {

event.element.textureAsset = this.activeAsset;
var url = "923103.json";

//load the scenes entity hierarchy
this.app.loadSceneHierarchy(url, function(err, parent){
if(!err){
callback(parent);
} else {
console.error (err);
}
});

}; // When we release the element assign the original texture if
// we are not hovering or the hover texture if we are still hovering
BtnStates.prototype.onRelease = function (event) {
event.element.textureAsset = this.hovered ? this.hoverAsset : this.originalTexture;
};

i have a code in my game ill add you to it

Our code is different than the one he/she is trying to achieve.

I have a problem that below the script I added I dont see the same menu you’re having in your editor with the main and current scenes, How can I see the entities found in the script

Screen Shot 2020-05-18 at 1.40.01 AM .

Ok, so the way I do it is a bit different. The more preferred way of doing it is by getting the scene IDs and destroying the old scene or hierarchy. I’ll demonstrate how to do this if you add me to your project. My username is dev01.

If you still need help, add me to your project. My username is dev01.

1 Like

Thanks a lot! I managed to fix it , Much appreciated :slight_smile:

1 Like