public bool Fire() { // Test if the gun is on cooldown because the energy was too low if (!isShootingPossible) { return(false); } // Shooting a new bullet if the gun is not on cooldown if (remainingTimeAfterShot <= 0) { // Signaling that the player started shooting again timeSinceLastBulletShot = 0f; // Creating the bullet bulletFactory.SendBullet(BulletDamage, BulletSpeed, typeOfBulletCreated, transform.position); // Resetting the timer to create a cooldown between shots remainingTimeAfterShot = BulletSpawnCooldown; // Decrementing the energy bar currentEnergy -= energyToShootInLine; // Checking if this last shot emptied the energy bar if (currentEnergy < 0) { isShootingPossible = false; } // Updating the UI slider if (this.tag == "PlayerBulletSpawner") { energyUIManager.EnergySliderUpdater(currentEnergy / maxEnergy); } return(true); } return(false); }