Here is the code first of all.
// var block
var ammo_charge : int;
var ammo_shot : ParticleEmitter;
var ammo_take : int;
var ammo_amount = 100;
var ammo_text : GUIText;
var mouse_button;
var ammo_gain : int;
// var setting block
ammo_shot = GetComponentInChildren(ParticleEmitter);
Screen.lockCursor = true;
// function block
function Update () {
ammo_amount += ((ammo_gain * Time.deltaTime) * ammo_charge); // charge the particle beam up
mouse_button = Input.GetMouseButton(0); // get mouse input
switch(mouse_button) {
case true:
ammo_charge = 0; // stop charging
ammo_shot.emit = true; // turn the emitter on
ammo_amount = ammo_amount - (ammo_take * Time.deltaTime); // remove ammo per second
break;
case false:
ammo_charge = 1; // start charging
ammo_shot.emit = false; // turn the emitter off
break;
}
if (ammo_amount <= 0) { // if the ammo is less than or equal to 0 stop fireing
ammo_shot.emit = false; // turn emitter off
ammo_amount = 0; // just incase it is less than 0
}
if (ammo_amount > 100) { // if ammo is greater than 100 reset to 100
ammo_amount = 100;
}
ammo_text.text = Int_to_String(Mathf.Round(ammo_amount));; // convert int to string
}
Now it should recharge the weapon but for some reason it does not and it always removes ammo at the same rate even when I change that rate in the script.