public override void Execute(Sis owner) { Weapon weapon = owner.inventory.currentWeapon; Weapon.RuntimeWeapon runtime = weapon.runtime; int bullets = runtime.currentBullets; isShooting.value = owner.isShooting; //Update Shooting Variables for FX and Ballistics Vector3 origin = (runtime.weaponTip == null ? runtime.modelInstance.transform.position : runtime.weaponTip.position); Vector3 dir = owner.movementValues.aimPosition - origin; //Shooting if (owner.isShooting && !startedShooting) { startedShooting = true; if (bullets > 0) { if (Time.realtimeSinceStartup - runtime.lastFired > weapon.fireRate) { runtime.lastFired = Time.realtimeSinceStartup; //Ballistics if (weapon.ballistics != null) { weapon.ballistics.Execute(owner, weapon, dir); } //Recoil and FX runtime.weaponFX.Shoot(dir); owner.aiming.StartRecoil(); //Decrement Bullets if (weapon.decrementBulletsOnShoot) { runtime.currentBullets--; if (runtime.currentBullets < 0) { runtime.currentBullets = 0; } } } } else //Reload if out of bullets { startedShooting = false; isShooting.value = false; owner.isShooting = false; owner.isReloading = true; } } //Delay if (startedShooting) { DelayStopShooting(owner); } }
public override void Execute(Sis owner) { Weapon weapon = owner.inventory.currentWeapon; Weapon.RuntimeWeapon runtime = weapon.runtime; isReloading.value = owner.isReloading; //Reloading if (owner.isReloading) { if (runtime.magazineSize < runtime.magazineCapacity) { if (runtime.currentBullets == 0) { //Chik Chik } else //Start Reloading! { owner.isShooting = false; //Start Animation if (owner.reloadingDoOnce) { Debug.Log("Starting reload"); int bulletsNeeded = runtime.magazineCapacity - runtime.magazineSize; if (runtime.currentBullets < bulletsNeeded) { bulletsNeeded = runtime.currentBullets; } owner.anim.SetBool("Reload", true); owner.anim.SetInteger("AmmoToLoad", bulletsNeeded); owner.reloadingDoOnce = false; owner.doneReloading = false; } else { //Reload at End of Animation if (owner.doneReloading) { Debug.Log("Finishing reload"); owner.anim.SetBool("Reload", false); owner.isReloading = false; owner.doneReloading = false; owner.reloadingDoOnce = true; owner.inventory.ReloadCurrentWeapon(); } } } } else //Magazine is Full. Can't Reload { owner.isReloading = false; } } }
// Update is called once per frame void Update() { if (sisVariable.value != null) { Weapon weapon = sisVariable.value.inventory.currentWeapon; Weapon.RuntimeWeapon runtimeWeapon = weapon.runtime; int magazine = runtimeWeapon.magazineSize; int total = runtimeWeapon.currentBullets; string ammoText = (magazine < 10 ? "0" : "") + magazine.ToString() + " | " + (weapon.infiniteTotalBullets ? "Inf." : total.ToString()); textUI.text = ammoText; } }
public void ReloadCurrentWeapon() { Weapon.RuntimeWeapon runtime = currentWeapon.runtime; int bulletsNeeded = runtime.magazineCapacity - runtime.magazineSize; if (currentWeapon.infiniteTotalBullets) { runtime.magazineSize += bulletsNeeded; return; } //Check if we have enough bullets for full reload if (runtime.currentBullets < bulletsNeeded) { runtime.magazineSize += runtime.currentBullets; runtime.currentBullets = 0; } else { runtime.magazineSize = runtime.magazineCapacity; runtime.currentBullets -= bulletsNeeded; } }
public override void Execute(Sis owner) { Weapon weapon = owner.inventory.currentWeapon; Weapon.RuntimeWeapon runtime = weapon.runtime; int bullets = runtime.currentBullets; //Reloading if (owner.isReloading) { int magazine = weapon.magazineBullets; if (bullets < magazine) { //Start Animation if (!owner.isInteracting) { owner.isInteracting = true; owner.PlayAnimation("Reload"); owner.anim.SetBool("InteractingHands", true); } else { //Reload at End of Animation if (!owner.anim.GetBool("InteractingHands")) { owner.isReloading = false; owner.isInteracting = false; owner.inventory.ReloadCurrentWeapon(); } } } else //Magazine is Full. Can't Reload { owner.isReloading = false; } } }