I am trying to make it so that when you are reloading you can’t shoot. I could set current ammo to 0 before currentAmmo is set to maxAmmo but I want to play a different animation when there is still a bullet left in the chamber. Any help?
var bullet : GameObject;
var weapon : GameObject;
var currentAmmo = 30;
var maxAmmo = 30;
var canFire : boolean = false;
var fireSound : GameObject;
var reloadSound : GameObject;
var tacReloadSound : GameObject;
var reloadTime : float = 1.4;
function Update ()
{
if (currentAmmo > 0)
canFire = true;
if (currentAmmo <= 0)
canFire = false;
if (currentAmmo > maxAmmo)
currentAmmo = maxAmmo;
if (Input.GetButtonDown("Fire") && canFire == true)
IsFiring ();
if (Input.GetButtonDown("Reload") && currentAmmo < maxAmmo)
Reload ();
canFire = false;
}
function IsFiring ()
{
if (currentAmmo > 0 && canFire == true)
currentAmmo --;
Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
weapon.animation.Play("Fire");
Instantiate(fireSound, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
if (currentAmmo == 0)
{
canFire = false;
Reload ();
}
}
function Reload ()
{
if (currentAmmo == 0)
animation.Play("TacReload");
Instantiate(reloadSound, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
canFire = false;
if (currentAmmo > 0)
animation.Play("Reload");
Instantiate(tacReloadSound, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
canFire = false;
yield WaitForSeconds(reloadTime);
canFire = false;
currentAmmo = maxAmmo;
}