Help is greatly appreciated! I tried everything I knew to fix this issue but I’m having trouble.
Here is the editor:PlayCanvas | HTML5 Game Engine
The script name is InputHandler.
This is the script, but the issue is at the end
var InputHandler = pc.createScript('inputHandler');
// initialize code called once per entity
InputHandler.prototype.initialize = function() {
};
// update code called every frame
InputHandler.prototype.update = function(dt) {
// Move Left when the A key is Pressed
if (this.app.keyboard.isPressed(pc.KEY_A)) {
this.entity.translate(0.1, 0, 0);
}
// Move Right when the D key is Pressed
if (this.app.keyboard.isPressed(pc.KEY_D)) {
this.entity.translate(-0.1, 0, 0);
}
// Move Right when the D key is Pressed
if (this.app.keyboard.isPressed(pc.KEY_W)) {
this.entity.translate(0, 0, 0.1);
}
// Move Right when the D key is Pressed
if (this.app.keyboard.isPressed(pc.KEY_S)) {
this.entity.translate(0, 0, -0.1);
}
if(this.app.keyboard.wasPressed(pc.KEY_SPACE))
{ var templateAsset = this.app.assets.find("PlayerLaser");
var position = this.entity.getPosition(); var entity = new pc.Entity();
var instance = templateAsset.resource.instantiate();
this.app.root.addChild(entity);entity.translate(position.x-2, position.y, position.z); entity.addChild(instance); }};
( var instance = templateAsset.resource.instantiate() is giving me the error. It kept saying this:
[InputHandler.js?id=110061170&branchId=db850bed-a8d9-4da1-88cc-0b60acd38da5:31]: Cannot read properties of null (reading ‘resource’)
TypeError: Cannot read properties of null (reading ‘resource’)