I keep getting an error for this code
var GunCollision = pc.createScript('GunCollision');
GunCollision.attributes.add('gun', {type: 'entity'});
gun = this.gun;
this.gun.enabled = false;
GunCollision.prototype.initialize = function() {
this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
this.entity.collision.on('triggerleave', this.onTriggerLeave, this);
};
GunCollision.prototype.onTriggerEnter = function() {
this.gun.enabled = true;
};
GunCollision.prototype.onTriggerLeave = function() {
this.gun.enabled = false;
};
but this works perfectly, because it is a copied script from this
var Collision = pc.createScript('collision');
Collision.attributes.add('screen', {type: 'entity'});
screen = this.screen;
this.screen.enabled = false;
Collision.prototype.initialize = function() {
this.entity.collision.on('triggerenter', this.onTriggerEnter, this);
this.entity.collision.on('triggerleave', this.onTriggerLeave, this);
};
Collision.prototype.onTriggerEnter = function() {
this.screen.enabled = true;
};
Collision.prototype.onTriggerLeave = function() {
this.screen.enabled = false;
};
this is the error (for gun collision) [uncaught type error: cannot set properties of undefined (setting ‘enabled’)]