// Add ammo to the players inventory when collision is detected public override void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { Debug.Log("Ammo gained"); PlayerManager.instance.PlayersInventory += amount; ammoUI.UpdateAmmoUI(); AudioManager.instance.Play("AmmoPickup"); Destroy(gameObject); // Destory the object once picked up } }
// Update is called once per frame void Update() { if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire && PlayerManager.instance.PlayersInventory > 0) // Fire1 is default button for Unity { nextTimeToFire = Time.time + 1f / fireRate; // Greater the fire rate the less time between shots Shoot(); // Accessing the bullet class method bullet.CreateBullet(); // Pushing the bullet in a direction by the bulletFowardForce variable bullet.TempRigidBody.AddForce(transform.right * bullet.BulletFowardForce); // Decrease the ammo PlayerManager.instance.PlayersInventory--; // Decrease the ammoUI ammoUI.UpdateAmmoUI(); } else if (Input.GetButtonDown("Fire1") && PlayerManager.instance.PlayersInventory <= 0) { AudioManager.instance.Play("DryFire"); } }
/// <summary> /// Consome uma municao e atualiza o valor na UI /// </summary> public void SpendAmmo() { loadedAmmo -= 1; ammoUI.UpdateAmmoUI(loadedAmmo, extraAmmo); }