private void ShootRPC(int shooterId) { var weapon = weaponHolder.currentWeapon; var consommable = consommableHolder.currentConsommable; if (weapon != null) { weapon.Fire(playerCameraTransform, playerID); if (weapon.currentAmmo > 0) { //play the weapon sound AudioManagerScript.Play3D(audioSource, weapon.weaponSound); } //the item can have changed since the player shoot. Update UI only if necessary var update = weapon == weaponHolder.currentWeapon; if (playerID == shooterId && update) { uiScript.SetAmmoCounter(weapon.currentAmmo); } } else if (consommable != null) { if (playerID == shooterId) { playerInventory.UseItem(playerInventory.currentSlotIndex); StartCoroutine(ApplyBonusOverTime(consommable.GetTime(), consommable.GetHealth(), consommable.GetShield())); } } }
/// <summary> /// Set the curretn active slot of the inventory (which is used when the player click) /// </summary> public void SwitchActiveIndex(int index) { //set the current ammo of the weapon in the inventory before the switch var currentActive = GetCurrentActive(); if (currentActive && currentActive.IsWeapon() && weaponHolder.currentWeapon) { currentActive.GetWeapon().SetCurrentAmmo(weaponHolder.currentWeapon.currentAmmo); } SetActiveItem(index); var item = inventory[index].GetItem(); if (item && item.IsWeapon()) { var weapon = item.GetWeapon(); weaponHolder.SetWeapon(weapon, weapon.currentAmmo); consommableHolder.SetConsommable(null); } else if (item && item.isConsommable()) { var consommable = item.GetConsommable(); consommableHolder.SetConsommable(consommable); weaponHolder.SetWeapon(null, 0f); playerUI.SetAmmoCounter(inventory[index].GetStackSize()); } else { weaponHolder.SetWeapon(null, 0f); consommableHolder.SetConsommable(null); } }