public void Fire() { if (currentNumberOfBullets > 0) { currentNumberOfBullets--; ammoIsChanged?.Invoke(currentNumberOfBullets, currentNumberOfMines); Instantiate(bullet, bulletSpawnPoint.position, transform.rotation); } else { Debug.Log("No bullets"); } }
public void Fire(GameObject target) { if (_weaponState != WeaponState.None) { return; } if (Ammo < 1) { Reload(); return; } _taget = target; _weaponState = WeaponState.Firing; _timer = FireTime; Ammo--; AmmoChangeEvent?.Invoke(Ammo, MaxAmmo); ShootBullet(); }
private void Update() { if (_timer > 0f) { _timer -= Time.deltaTime; } if (_timer <= 0f) { if (_weaponState == WeaponState.Firing) { _timer = 0f; _weaponState = WeaponState.None; } else if (_weaponState == WeaponState.Reloading) { _weaponState = WeaponState.None; _timer = 0f; Ammo = MaxAmmo; AmmoChangeEvent?.Invoke(Ammo, MaxAmmo); } } }