Keyboard input not working

I am a begginer to using PlayCanvas, and I made a small program that receives keyboard input to change the colour of a cube. However when I run the program using the editor, it will not work, as when I press the key ‘A’, on which the program is supposed to change the colour to the cube, nothing will happen.

Code:
https://playcanvas.com/editor/code/500649?tabs=8906303

Editor:
https://playcanvas.com/editor/scene/546321

Change:

    this.app.on(pc.EVENT_KEYDOWN, this.onKeyDown,this);
    this.app.on(pc.EVENT_KEYUP, this.onKeyUp,this);

To:

    this.app.keyboard.on(pc.EVENT_KEYDOWN, this.onKeyDown,this);
    this.app.keyboard.on(pc.EVENT_KEYUP, this.onKeyUp,this);

I changed those 2 lines, but it is still not working.

But your event functions are now firing, right?

There’s another problem. You have exposed two scripts attributes at the top of your script file. You need to:

  1. Select the Entity with the ‘test’ script applied.
  2. Hit the Parse icon. Your two script attributes will appear.
  3. Drag materials onto the script attributes.

2 posts were split to a new topic: Entity won’t move on a key press