public void RpcObtainProjectile(int[] indexes) { Debug.Log("Obtaining projectiles"); // We need to switch projectile if we don't have any projectile yet bool switchProjectile = _projectiles.Count == 0; foreach (int index in indexes) { if (_allProjectiles.Count > index) { _allProjectiles[index].InPossession = true; if (!_projectiles.Contains(_allProjectiles[index])) { _projectiles.Add(_allProjectiles[index]); } } } // If the number of projectiles in possession is now superior to 0, and we previously had nothing, then we switch to the first projectile if (switchProjectile && _projectiles.Count > 0) { _selectedProjectileIndex = 0; _selectedProjectile = _projectiles[_selectedProjectileIndex]; } }
public void RpcSwitchProjectile(int increment) { _selectedProjectileIndex += increment; if (_selectedProjectileIndex >= _projectiles.Count) { _selectedProjectileIndex = 0; } if (_selectedProjectileIndex <= -1) { _selectedProjectileIndex = _projectiles.Count - 1; } _selectedProjectile = _projectiles[_selectedProjectileIndex]; if (_player.isLocalPlayer) { PlaySwitchProjectileSound(); } }
private void ReInitializeProjectiles() { _projectiles.Clear(); foreach (EquippedProjectile projectile in _allProjectiles) { if (projectile.InPossession) { _projectiles.Add(projectile); } } if (_projectiles.Count > 0) { _selectedProjectileIndex = 0; _selectedProjectile = _projectiles[_selectedProjectileIndex]; } else { _selectedProjectileIndex = -1; _selectedProjectile = null; } }