void ChangeWeapon() { RangedWeapon otherWeapon; if (currentWeapon == primaryWeapon && baseWeapon != null) { otherWeapon = baseWeapon; anim.SetBool("Primary", false); } else if (currentWeapon == baseWeapon && primaryWeapon != null) { otherWeapon = primaryWeapon; anim.SetBool("Primary", true); } else { return; } //Deactivate current weapon currentWeapon.OnAmmoChanaged -= CurrentWeapon_AmmoChanged; currentWeapon.IsBeingUsed(false); currentWeapon = otherWeapon; //Activate new weapon currentWeapon.Reset(); currentWeapon.OnAmmoChanaged += CurrentWeapon_AmmoChanged; currentWeapon.IsBeingUsed(true); OnAmmoChanged?.Invoke(CurrentWeapon.Magazine); }
void Awake() { anim = GetComponent <Animator>(); col = GetComponent <Collider>(); rb = GetComponent <Rigidbody>(); //To drag in character and test easier if (Player == null) { Player = new Player(); SetupPlayer(Player); } //Subscribe to stat events stats.OnDeath += Stats_OnDeath; stats.OnStatChanged += Stats_OnStatChanged; //Equip base weapon if any if (baseWeapon != null) { baseWeapon.Equip(weaponParent); currentWeapon = baseWeapon; baseWeapon.OnAmmoChanaged += CurrentWeapon_AmmoChanged; OnAmmoChanged?.Invoke(baseWeapon.Magazine); } }
//TODO: Make one Equip method for each type of equippable /// <summary> /// Returns false if Weapon is null /// </summary> public bool EquipWeapon(Weapon weap) { if (weap == null) { return(false); } if (weap is RangedWeapon) { //Equip new weapon RangedWeapon rangedWeap = weap as RangedWeapon; anim.SetBool("Primary", true); currentWeapon?.IsBeingUsed(false); rangedWeap.Equip(weaponParent); if (PrimaryWeapon != null) { Destroy(PrimaryWeapon.gameObject); } currentWeapon = primaryWeapon = rangedWeap; primaryWeapon.OnAmmoChanaged += CurrentWeapon_AmmoChanged; OnAmmoChanged?.Invoke(primaryWeapon.Magazine); return(true); } return(false); }
private void Update() { if (Input.GetButton("Fire1") && Time.time > canFire) { ammoCount--; OnAmmoChanged?.Invoke(ammoCount); canFire = Time.time + fireRate; } else if (Input.GetButtonUp("Fire1")) { canFire = Time.time; } }
public bool TrySpendAmmo() { if (ammo > 0) { ammo--; OnAmmoChanged?.Invoke(this, EventArgs.Empty); return(true); } else { return(false); } }
private void Start() { ammoCount = maxAmmoCount; OnAmmoChanged?.Invoke(ammoCount); }
public void HandleOnAmmoChanged() { OnAmmoChanged?.Invoke(); }
/// <summary> /// Calls the OnAmmoChanged event when the current weapons OnAmmoChanged event is called /// </summary> /// <param name="mag">The current magazine</param> void CurrentWeapon_AmmoChanged(Magazine mag) { OnAmmoChanged?.Invoke(mag); }
public static void RaiseAmmoChanged(AmmoType ammoType, int change) => OnAmmoChanged?.Invoke(ammoType, change);
public void Reload() { ammo = GetAmmoMax(); OnAmmoChanged?.Invoke(this, EventArgs.Empty); }