[SOLVED] Toggle Pause Menu Question

Hello! I am making a pause menu for my game, and to toggle the pause menu, you have to press the key p. But for some reason it’s not working. Here is my script. Thank you!

var Pause = pc.createScript('pause');

// initialize code called once per entity
Pause.prototype.initialize = function() {
   this.toggle = 0;

};

// update code called every frame
Pause.prototype.update = function(dt) {
      var app = this.app;
      if (app.keyboard.wasPressed(pc.KEY_P)) {
         if (this.toggle === 0) {
            this.app.timeScale = 0;
            this.toggle = 1;
         }
         if (this.toggle === 1) {
            this.app.timeScale = 1;
            this.toggle = 0;
         }
      }
    

};

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

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

Hi @SoySauceStudios!

Is the script attached to an entity?

Yeah it’s attached to the 2d screen entity in my scene.
If you need my project link, here it is:
https://playcanvas.com/project/1143490/overview/the-complex
The script would be found in the scene “level fun” in the 2d screen entity. Thank you!

Oh wait never mind! I figured it out. Thank you @Albertos !

1 Like