I’m trying to animate a gun reloading and firing and so far everythings been working rather well, however when I tried to set up the script to only allow the gun to fire when loaded (or when wound in the case of this gun) and the allow the gun to be loaded a set amount of times. When I run the game the script returns no errors but I can only reload the gun once or (sometimes) twice rather than three times (what the AmmoCapacity variable is set to) and sometimes I get two shots out of one reload.
Thanks in advance - heres the full code
var AmmoCapacity : int;
//var DefaultBullet : GameObject;
static var currentAmmo = 0;
function Update () {
if (Input.GetAxis ("Reload") )
{
reloader();
}
if ( Input.GetAxis ("Fire1") )
{
firing();
}
}
function reloader ()
{
if (currentAmmo < AmmoCapacity)
{
animation.Play("reload",PlayMode.StopAll);
yield WaitForSeconds (animation.clip.length);
currentAmmo ++;
}
}
function firing ()
{
if(currentAmmo > 0)
{
animation.Play("fire",PlayMode.StopAll);
yield WaitForSeconds (animation.clip.length);
currentAmmo --;
}
}