I have a shooting script, however i want an attribute that lets me toggle in editor whethor or not the weapon is fully automatic or not
var Shoot = pc.createScript('shoot');
Shoot.attributes.add('maxAmmo', {type : 'number', default : 30});
Shoot.attributes.add('range', {type : 'number', default : 30});
Shoot.attributes.add('text', {type : 'entity'});
Shoot.attributes.add('text2', {type : 'entity'});
Shoot.attributes.add('particleSys', {type : 'entity'});
Shoot.attributes.add('debugColor1', {type : 'rgba'});
Shoot.attributes.add('gunPoint', {type : 'entity'});
Shoot.attributes.add('hitImpulse', {type : 'number', default : 10});
Shoot.attributes.add('damage', {type : 'number', default : 10});
Shoot.attributes.add('fireRate', {type : 'number', default : 10});
Shoot.attributes.add('camera', {type : 'entity'});
Shoot.attributes.add('automatic', {type : 'boolean'});
Shoot.attributes.add('manual', {type : 'boolean'});
// initialize code called once per entity
Shoot.prototype.initialize = function() {
this.currentAmmo = 0;
this.currentAmmo = this.maxAmmo;
this.canShoot = true;
this.TimeSinceGameStarted = 0;
this.rateOfRire = 0;
};
// update code called every frame
Shoot.prototype.update = function(dt) {
this.TimeSinceGameStarted += dt;
var from = this.gunPoint.getPosition();
var to = this.camera.camera.screenToWorld(screen.width / 2 , screen.height / 2 - 37, this.range);
var result = this.app.systems.rigidbody.raycastFirst(from, to);
this.rateOfRire -= dt;
if(this.currentAmmo === 0)
{
this.canShoot = false;
}
else
{
this.canShoot = true;
}
if(this.app.mouse.wasPressed(pc.MOUSEBUTTON_LEFT) && this.canShoot === true && this.manual)
{
this.particleSys.particlesystem.reset();
this.particleSys.particlesystem.play();
this.particleSys.particlesystem.reset();
if(result)
{
result.entity.collision.entity.rigidbody.applyImpulse(this.camera.forward.scale(this.hitImpulse), result.normal);
this.currentAmmo -= 1;
}else
{
return;
}
if(result.entity.name == 'fastboi zombie')
{
result.entity.script.target.TakeDamage(this.damage);
}
}
if(this.app.mouse.isPressed(pc.MOUSEBUTTON_LEFT) && this.canShoot === true && this.automatic && this.TimeSinceGameStarted >= this.rateOfRire)
{
this.particleSys.particlesystem.play();
this.particleSys.particlesystem.reset();
this.currentAmmo -= 1;
this.rateOfRire = this.TimeSinceGameStarted += 100 + 10 / this.fireRate;
if(result)
{
result.entity.collision.entity.rigidbody.applyImpulse(this.camera.forward.scale(this.hitImpulse), result.normal);
}else
{
return;
}
if(result.entity.name == 'fastboi zombie')
{
result.entity.script.target.TakeDamage(this.damage);
}
this.rateOfRire = this.fireRate;
}
if(this.app.keyboard.wasPressed(pc.KEY_R))
{
this.currentAmmo = this.currentAmmo + (this.maxAmmo - this.currentAmmo);
}
this.text.element.text = this.currentAmmo;
this.text2.element.text = '/ ' + this.maxAmmo;
};