[SOLVED] loadScene is not defined


I am trying to use the loadScene on my project to jumpscare the player by changing to a jumpscare scene, What I want to do is, when the player touches the collision box I want to load the jumpscare scene

this is my code

var JumpScare = pc.createScript('jumpScare');

// initialize code called once per entity
JumpScare.prototype.initialize = function() {
    this.entity.collision.on('triggerenter', this.onTriggerEnter, this)

JumpScare.attributes.add("sceneName", { type: "string", default: "", title: "Scene Name to Load" });

JumpScare.prototype.onTriggerEnter = function(entity) {
         loadScene(this.sceneName, { hierarchy: true, settings: false }, function (err, parentEntity) {
            if (err) {
            } else {
                console.log('Scene \'' + this.sceneName + '\' Loaded');
        }, this);

but when ever I try to run it, the console says “loadScene is not defined”

Hey @teczito and Welcome, loadScene function is not defined in your script. You can define the function within the script to make it work.

Alternatively, you can use the code below to change the scene.

this.app.scenes.changeScene('Some Scene Name');


1 Like

I’ve tried that

What is the result?

never mind I tried it again and it worked

1 Like