My gun script is causing my gun to randomly fill up the max ammo, and I’m not sure why.
var projectile : Rigidbody;
var speed = 10;
var Ammo = 6;
var Reloading : boolean = false;
var TexturesToLoad : Texture2D[];
var guiTex : GUITexture;
function Start()
{
guiTex.texture = TexturesToLoad[6];
}
function Update () {
guiTex.texture = TexturesToLoad[Ammo];
if (Input.GetButtonDown ("Fire1"))
{
if (Ammo >0)
{
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
Destroy (clone.gameObject, 3);
Ammo -= 1;
}
else
{
Reloading = true;
Reload();
}
}
if (Input.GetButtonDown("Reload"))
{
Reloading = true;
Reload();
}
}
function Reload()
{
yield WaitForSeconds(5);
Ammo = 6;
Reloading = false;
}