I need help changing scenes

i don’t know how to change scenes with a button

i dont want to be rude or anything but a simple search could gave you, all you need:
https://developer.playcanvas.com/en/tutorials/changing-scenes/

yeah well im really not good at coding and i dont know how to make it so when you press the button it switches scenes

well i guess coding is inevitable.

true hahaha

Hi @the_amazing_ella! Maybe you can use the project below, that is made by @eproasim, as example.

https://playcanvas.com/project/756176/overview/scene-manager

its not working.

Hi @the_amazing_ella,

What are you having trouble with?

I would love to update the comments in the project to help other users be less confused with how it works.

1 Like

here ill show you my game https://playcanvas.com/editor/scene/1148644

Hi @the_amazing_ella,

If you take a look at the project linked by @Albertos, you will see that there is a Scene called ‘Init’ that that contains and entity called ‘Scene Manager’. That entity has the script applied to it and has the name of the first scene it is supposed to load.

In your case, you would want to create a scene called ‘Init’ and add an enity with the sceneManager script applied. Once that is done, you can type ‘start scene’ in the editor under the ‘Start Scene’ field of the script. You may have to click the ‘parse’ button first on the script to get it to appear. Once that is done, you can launch the ‘Init’ scene and it will take you directly to your ‘start scene’ scene. From there whenever you want to change to another scene, you will want to use button events to app.fire() the ‘changeScene’ event and send along the name of the scene you want to go to.

That would look something like this:

var ExampleButton = pc.createScript('exampleButton');

ExampleButton.attributes.add('targetScene', {
     type: 'string',
     title: 'Target Scene',
     description: 'The scene you want to go to'
});

ExampleButton.prototype.initialize = function() {
     this.entity.button.on('click', this.onClick, this);
};

ExampleButton.prototype.onClick = function() {
     var app = this.app;

     app.fire('changeScene', this.targetScene);
};
1 Like

i dont get any of this

Hi @the_amazing_ella,

Where are you getting stuck? With specific roadblocks, we can help you understand the fundamentals and get you on your way to coding on your own.

1 Like