IEnumerator FinishReload(float duration, bool perfect) { Debug.Log("reload -> " + perfect + " wait: " + duration); yield return(new WaitForSeconds(duration)); Debug.Log("endreload"); reloading = false; slider.transform.localPosition = new Vector3(startBar.transform.localPosition.x, slider.transform.localPosition.y, slider.transform.localPosition.z); // Now we are going to extract the leftAmmo from inventory, and add to the actualCLip //NOTE: only the new ammo added will be critic if is a perfect reload (so if we reload with 29/30 ammo, only 1 shoot wil be critical) if (InventoryManager.instance) { int ammoToFill = maxClip - ammo; // how much to fill the actual clip? int addedAmmo = InventoryManager.instance.ExtractAmmoFromInventory(ammoToFill, ammoType); // maybe the inventory has not enough, so just add how much left ammo += addedAmmo; if (perfect) { //IS A PERFECT RELOAD SO ADD CRITICAL AMMO!!! perfectAmmo = addedAmmo; } else { // IS A NORMAL RELOAD perfectAmmo = 0; } } weaponStatus = RELOADSTATE.READY; UIManager.instance.ReloadAmmo(ammoType, maxClip, ammo, perfectAmmo); reloadBar.SetActive(false); }
public void ManualReload() { Debug.Log("stop reloading"); // float value = slider.rectTransform.anchoredPosition.x; float value = actualTimeInReload; if (value >= perfectReload && value <= activeReload) { Debug.Log("PERFECT!!!"); weaponStatus = RELOADSTATE.PERFECT; PerfectReload(value); } else if (value >= activeReload && value <= activeReloadEnd) { Debug.Log("ACTIVE!!!"); weaponStatus = RELOADSTATE.ACTIVE; ActiveReload(value); } else { weaponStatus = RELOADSTATE.FAILED; Debug.Log("FAIL!!!"); FailedReload(value); } if (reloadRoutine != null) { StopCoroutine(reloadRoutine); } }
// start the reload coroutine public void BeginReload() { weaponStatus = RELOADSTATE.RELOADING; reloading = true; actualTimeInReload = 0f; slider.color = Color.white; reloadBar.SetActive(true); reloadRoutine = StartCoroutine(Reloading()); }