Hi, I’m a beginner to playcanvas and my code isn’t working. i’m trying to get a entity to disappear when i press the arrow keys. When i try this it just says on the launch page “Uncaught TypeError: Cannot read property ‘keyboard’ of undefined”. How do i fix this? Here is my code:
var PlayerSwapTyler = pc.createScript(‘playerSwapTyler’);
var keyboard = new pc.Keyboard(window);
There are actually quite a few things you shouldn’t be doing in the code you’ve posted. Never initialize events like this.app.keyboard.on(pc.EVENT_KEYDOWN, this.onKeyDown,this); in the update function. That’s what the init function is for. Unless you really need the console.log in the update function, remove it, because it will unnecessarily slow down the browser.
The following is how you would want to disable an entity on the press of the down arrow key.
Its still not working so i’ll post a link to my project so you can take a look. The one i’m working on right now is the scene called shop and the code is called “player_swap_tyler.js” Here is the linkhttps://playcanvas.com/project/719828/overview/coins–and-