Change scene with a timer

How would I edit this script to make it so it would change the scene to the name of the scene. The name of the scene is in an attribute.

var Example2 = pc.createScript('example2');
Example2.attributes.add('durationSecs', {type: 'number'});
Example2.attributes.add('sceneName', {type: 'string'});


// initialize code called once per entity
Example2.prototype.initialize = function() {
    this._paused = false;
    this._timerHandle = pc.timer.add(this.durationSecs, this.moveToRandomPosition, this);
    
    this.on('destroy', function() {
        pc.timer.remove(this._timerHandle);
    }, this);
};


// update code called every frame
Example2.prototype.update = function(dt) {
    if (this.app.keyboard.wasPressed(pc.KEY_P)) {
        this._paused = !this._paused;
        this.app.timeScale = this._paused ? 0 : 1;
    }
    
    if (this.app.keyboard.wasPressed(pc.KEY_R)) {
        pc.timer.remove(this._timerHandle);
    }
};


Example2.prototype.moveToRandomPosition = function () {
     //what would i put here to change scenes?
};

// swap method called for script hot-reloading
// inherit your script state here
// Example.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/

Hi @Mason_Rocchio! Below the manual page about changing scenes.

https://developer.playcanvas.com/en/user-manual/packs/loading-scenes/

1 Like

I just used a button, saves time. Did help though on the page above Thanks!

1 Like