public void Reload() { Weappon weapponComponentInHand = weappons[inHandWeaponIndex].GetComponent <Weappon>(); if (!weapponComponentInHand.isMelee) { counterForReload += Time.deltaTime; counterPerBullet += Time.deltaTime; reloadCircle.SetActive(true); reloadCircle.GetComponent <Image>().fillAmount = counterForReload / timeOfReload; if (counterPerBullet > weapponComponentInHand.timeReloadPerBullet && weapponComponentInHand.totalBullets > 0 && weapponComponentInHand.bulletsInMagazine < weapponComponentInHand.maxBulletInMagazine) { weapponComponentInHand.bulletsInMagazine++; weapponComponentInHand.totalBullets--; refreshAmmoQuantityAndUI(); counterPerBullet = 0; //sound reload } else if (weapponComponentInHand.totalBullets <= 0 || weapponComponentInHand.bulletsInMagazine >= weapponComponentInHand.maxBulletInMagazine) { StopReload(); } } else { reload = false; } }
public void refreshAmmoQuantityAndUI() { Weappon weapponComponetInHand = weappons[inHandWeaponIndex].GetComponent <Weappon>(); Weappon weapponComponetSlot = weappons[slotWeaponIndex].GetComponent <Weappon>(); inHandWeaponImage.sprite = weapponComponetInHand.uiImage; savedWeaponImage.sprite = weapponComponetSlot.uiImage; inHandBulletQuantityText.text = weapponComponetInHand.bulletsInMagazine + "/" + weapponComponetInHand.totalBullets; savedBulletQuantityText.text = weapponComponetSlot.bulletsInMagazine + "/" + weapponComponetSlot.totalBullets; }
public void calculateTimeReload() { Weappon weapponComponentInHand = weappons[inHandWeaponIndex].GetComponent <Weappon>(); int bulletsToReload = weapponComponentInHand.maxBulletInMagazine - weapponComponentInHand.bulletsInMagazine; int howManyBulletsAreMissing = bulletsToReload - weapponComponentInHand.totalBullets; if (howManyBulletsAreMissing <= 0) { howManyBulletsAreMissing = 0; } bulletsToReload -= howManyBulletsAreMissing; timeOfReload = bulletsToReload * weapponComponentInHand.timeReloadPerBullet; }
public void Attack() { Weappon weapponComponent = weappons[inHandWeaponIndex].GetComponent <Weappon>(); if (reload) { StopReload(); } if (weapponComponent.isMelee) { } else if (weapponComponent.isMachineGun) { } else { if (weapponComponent.bulletsInMagazine > 0) { weapponComponent.bulletsInMagazine--; CmdShoot(); refreshAmmoQuantityAndUI(); } } }