Updating level number on a new scene

Hello! this may seem very simple but I am quite confused. Can I ask how I am able to update the level number on my game bar script? SInce I am on level 2 and it still displays level 1. Thank you.

Here is my gamebar script for your reference:

var GameBarScript = pc.createScript('gameBarscript');

//adding attributes for each text entity
GameBarScript.attributes.add('legoTxt', {type:'entity'});
GameBarScript.attributes.add('levelTxt', {type:'entity'});

//initialize each text element
var legoCount = 0;
var level = 1;


// initialize code called once per entity
GameBarScript.prototype.initialize = function() {

// set values for each attribute
this.legoTxt.element.text = legoCount;
this.levelTxt.element.text = level;

};

// update code called every frame
GameBarScript.prototype.update = function(dt) {

};

``

Here is the link for my simple game. Thank you again!
https://playcanvas.com/editor/scene/2383233

Somewhere you should have a level++;

1 Like