public void AddWeapon(Weapon.Model model) { if (!Weapons.ContainsKey(model)) { GameObject weaponGO = Instantiate(Resources.Load <GameObject>( Paths.Prefabs.WEAPONS + model.ToString())); weaponGO.transform.SetParent(weaponPoint); weaponGO.transform.localPosition = Vector3.zero; weaponGO.transform.localEulerAngles = Vector3.zero; Weapon weapon = weaponGO.GetComponent <Weapon>(); Weapons.Add(model, weapon); CurrentWeaponModel = model; SetCurrentWeaponGameObject(); } else { Weapons[model].Reload(); if (model == CurrentWeaponModel) { CurrentWeaponModel = model; } } }
public void SwitchWeapon(int number) { if (number < Weapon.ModelsNumber) { Weapon.Model model = (Weapon.Model)number; Weapon weapon; if (Weapons.TryGetValue(model, out weapon)) { CurrentWeaponModel = weapon.ModelType; SetCurrentWeaponGameObject(); } } }
public void SwitchWeaponWithDirection(int direction) { if (Weapons.Count > 0) { int current = (int)currentWeaponModel; int next = (current + direction); if (next < 0) { current = Weapon.ModelsNumber + next; } else { current = next % Weapon.ModelsNumber; } currentWeaponModel = (Weapon.Model)current; if (!Weapons.ContainsKey(currentWeaponModel)) { SwitchWeaponWithDirection(direction); } CurrentWeaponModel = currentWeaponModel; SetCurrentWeaponGameObject(); } }