link:PlayCanvas | HTML5 Game Engine
is this good
@MATURE At first glance I see you have the scene change script attached to both the button and itās text element. Not sure this will work.
it didnt work
@MATURE Could you let me know what didnāt work. As I see from the project link you have provide there have been no changes.
Both the Button and the Text have the script.
Hi @MATURE!
It seems there is a problem with your script.
Probably you renamed the script?
If you parse the script you can see this in the editor too.
I suggest to remove the script from the entity and add it again.
@MATURE @albertos is correct. You will need to remove the script from the txt element and keep it removed. Also, remove it from the button. There is an error in your script. Here is the correction.
var Scenes = pc.createScript('scenes');
Scenes.attributes.add('sceneName', {type: 'string'});
// initialize code called once per entity
Scenes.prototype.initialize = function() {
this.entity.button.once('click', function() {
this.app.scenes.changeScene(this.sceneName);
}, this);
};
The very first line is where the issue is. Notice that the var Is Scenes with capital S. The pc.createScript must be different. As you can see I just changed it to scene no capital S. Save this correction and re add to your button.
You also seem to have a very large asset which is the mandalorian ship. It may take long to load this.
it changes the scenes but it says
Cannot read properties of undefined (reading āonceā)
@MATURE I have loaded your project and ran it. I am not seeing the error but did notice your changes to the Menu.js script. Is there a reason you have decided to make the button a variable?
var Menu = pc.createScript('menu');
Menu.attributes.add('sceneName', {type: 'string'});
Menu.prototype.initialize = function() {
var button = this.entity.button;
if (button) {
button.once('click', function() {
this.app.scenes.changeScene(this.sceneName);
}, this);
}
};
I am not really sure if using the same term ābuttonā is causing what you are seeing or not. I am using Chrome what browser are you using?
also chrome
it allows easier and more efficient access to the button component throughout the script. This way, the script can attach an event listener to the buttonās āclickā event, and when clicked, it will change the scene to the one specified by the āsceneNameā attribute.
now it doesnt show the error thanks