public void destroy() { if (audio != null) { audio.destroy(); } }
public void shoot() { if (!canShoot()) { return; } if (this.gameObject == null) { return; } if (this.tags == 0) { this.tags = this.gameObject.getTags() | Tags.node | Tags.shot; } this.shots++; if (this.shots >= this.magazineSize) { if (this.useMagazine) { this.nextShotTime = Time.getTime() + this.magazineReloadTime; } else { this.nextShotTime = Time.getTime() + this.reloadTime; } this.shots = 0; } else { this.nextShotTime = Time.getTime() + this.reloadTime; } if (this.usePhysics && this.gameObject.getRigidBody() != null) { this.shotSpeedVector.x += this.gameObject.getRigidBody().speed.x; this.shotSpeedVector.y += this.gameObject.getRigidBody().speed.y; } float randomX = Util.randomNumber(0, this.accuracy); float randomY = Util.randomNumber(0, this.accuracy); final int upDown = Util.randomNumber(0, 1); final int leftRight = Util.randomNumber(0, 1); if (upDown == 1) { randomY = -randomY; } if (leftRight == 1) { randomX = -randomX; } this.shotSpeedVector.x += randomX; this.shotSpeedVector.y += randomY; this.shotPosition.x = this.gameObject.transform.position.x; this.shotPosition.y = this.gameObject.transform.position.y; this.shotPosition.x += offset.x; this.shotPosition.y += offset.y; if (fire(this.shotPosition)) { if (audio != null) { audio.playOnce(); } } this.shotSpeedVector.x -= randomX; this.shotSpeedVector.y -= randomY; if (this.usePhysics && this.gameObject.getRigidBody() != null) { this.shotSpeedVector.x -= this.gameObject.getRigidBody().speed.x; this.shotSpeedVector.y -= this.gameObject.getRigidBody().speed.y; } }