IEnumerator SwitchWeapon(int index) { isSwitching = true; index = Mathf.Clamp(index, 0, equippedWeapons.Length - 1); for (int i = 0; i < equippedWeapons.Length; i++) { RangedWeapon rw = equippedWeapons[i]; if (equippedWeapons[i].gameObject.activeSelf == true) { StartCoroutine(rw.Holster()); print(rw.name + " has been holstered."); } } yield return(new WaitUntil(() => AllOtherWeaponsHolstered())); StartCoroutine(equippedWeapons[index].Draw()); print(equippedWeapons[index].name + " has been drawn."); currentWeaponIndex = index; yield return(new WaitUntil(() => equippedWeapons[index].isSwitchingWeapon == false)); isSwitching = false; }
IEnumerator SwitchWeaponAndFiringMode(int weaponIndex, int firingModeIndex) { weaponIndex = Mathf.Clamp(weaponIndex, 0, equippedWeapons.Length - 1); firingModeIndex = Mathf.Clamp(firingModeIndex, 0, equippedWeapons[weaponIndex].firingModes.Length); if (equippedWeapons[weaponIndex] != equippedWeapons[currentWeaponIndex]) { isSwitching = true; for (int i = 0; i < equippedWeapons.Length; i++) { RangedWeapon rw = equippedWeapons[i]; if (equippedWeapons[i].gameObject.activeSelf == true) { StartCoroutine(rw.Holster()); } } yield return(new WaitUntil(() => AllOtherWeaponsHolstered())); StartCoroutine(equippedWeapons[weaponIndex].Draw()); currentWeaponIndex = weaponIndex; yield return(new WaitUntil(() => equippedWeapons[weaponIndex].isSwitchingWeapon == false)); isSwitching = false; print("Weapon switch finished"); } if (equippedWeapons[weaponIndex].firingModeIndex != firingModeIndex) { print("Index is different"); equippedWeapons[weaponIndex].SwitchWeaponMode(firingModeIndex); } }