// Play Reload private IEnumerator PlayReload() { isReloading = true; singleShotReady = true; FirstPersonWeaponSway.IronsightUnzoom(); while (FirstPersonWeaponSway.ironsightZooming || FirstPersonWeaponSway.isPlaying) { yield return(null); } float reloadTime = .15f; if (fpWeaponSway != null && fpWeaponSway.reloadClip != null) { reloadTime = fpWeaponSway.reloadClip.length; } if (reloadSFX != null) { reloadTime = reloadSFX.length; } if (reloadSFX != null && fpWeaponSway != null && fpWeaponSway.reloadClip != null) { reloadTime = Mathf.Min(reloadSFX.length, fpWeaponSway.reloadClip.length); } if (fpWeaponSway != null) { fpWeaponSway.PlayReloadAnimation(); } m_Audio.pitch = Time.timeScale; m_Audio.PlayOneShot(reloadSFX); float elapsed = 0f; while (elapsed < reloadTime) { elapsed += Time.deltaTime; yield return(null); } int missingAmmo = Mathf.Max(0, maxAmmo - currentSlot.currentAmmo); int invAmmo = AmmoBackpack.GetCurrentAmmo(currentSlot.ammoIndex); currentSlot.currentAmmo += Mathf.Min(Mathf.Max(0, invAmmo), missingAmmo); invAmmo = Mathf.Max(0, invAmmo -= missingAmmo); AmmoBackpack.SetCurrentAmmo(currentSlot.ammoIndex, invAmmo); HudElements.WeaponInformer.UpdateCurrentAmmoInfo(currentSlot.currentAmmo); HudElements.WeaponInformer.UpdateAllAmmoInfo(invAmmo); isReloading = false; }
// Change Weapon private static IEnumerator ChangeWeapon() { while (FirstPersonWeaponSway.isPlaying) { yield return(null); } if (FirstPersonWeaponSway.ironsightZoomed) { FirstPersonWeaponSway.IronsightUnzoom(); while (FirstPersonWeaponSway.ironsightZooming) { yield return(null); } } if (weaponGo.activeSelf) { if (weaponsCount > 0) { m_Audio.PlayOneShot(m_Instance.switchWeapon); } weaponGo.GetComponentInChildren <FirstPersonWeaponSway>().DropoutAnimation(); } while (FirstPersonWeaponSway.isChanging) { yield return(null); } weaponGo.SetActive(false); if (weaponIndex >= 0) { isSubweapon = false; m_Weapon = m_Instance.weapons[weaponIndex].weapon; weaponGo = m_Weapon.gameObject; m_Firearm = m_Weapon as Firearms; weaponGo.SetActive(true); weaponGo.GetComponentInChildren <FirstPersonWeaponSway>().DropinAnimation(); } UpdateHud(true); }
// Use Item internal static void UseItem() { if (inputUse || crosshairMode == ECrosshairMode.Cancel || !PlayerCharacter.Instance.isAlive || FirstPersonWeaponSway.ironsightZooming || FirstPersonWeaponSway.isChanging || FirstPersonWeaponSway.isPlaying) { return; } if (FirstPersonWeaponSway.ironsightZoomed) { FirstPersonWeaponSway.IronsightUnzoom(); return; } inputUse = true; }
// Start protected virtual void Start() { owner = GetComponentInParent <ICharacter>(); if (owner == null) { Debug.LogError("Weapon Owner is not found! Error in: " + this.name); return; } if (owner.isPlayer) { m_Audio = GetComponentInParent <AudioSource>(); fpWeaponSway = GetComponentInChildren <FirstPersonWeaponSway>(); if (firingModes.Length >= 1) { firingModeIndex = 0; firingMode = firingModes[firingModeIndex]; } } else if (owner.isNPC) { firingMode = EFiringMode.Automatic; m_Audio = GetComponentInChildren <AudioSource>(); if (m_Audio == null) { m_Audio = owner.m_Audio; if (m_Audio != null) { return; } Debug.LogWarning("AudioSource is not found! Warning in " + this.name); m_Audio = gameObject.AddComponent <AudioSource>(); } } m_Audio.SetupForSFX(); }
// OnDisable void OnDisable() { instance.StopCoroutine("ChangeWeapon"); FirstPersonWeaponSway.FullReset(); }
// OnEnable void OnEnable() { moveSpeed = useSway ? fpMoveSpeed : 1f; instance = this; }