I am trying to make it so that when your ammo runs to zero, you stop shooting and the print says "out of ammo" Ive gotten the ammo to work on the UI but it keeps shooting after zero and "out of ammo" keeps showing up before I run out.
Code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class GunScript : MonoBehaviour {[INDENT]public Rigidbody grenade; public int projectileSpeed; public int ammo; public Text ammoValue; void Update()[/INDENT][INDENT]{[/INDENT][INDENT]if (Input.GetButtonDown("Fire1"))[/INDENT][INDENT=2]{[/INDENT][INDENT=3]Rigidbody clonedBall; clonedBall = Instantiate(grenade, transform.position, transform.rotation); clonedBall.velocity = transform.TransformDirection(Vector3.forward * projectileSpeed); if (ammo >= 0) {[/INDENT][INDENT=4]ammo--; ammoValue.text = ammo.ToString(); print("out of ammo");[/INDENT][INDENT=3]}[/INDENT][INDENT=2]}[/INDENT][INDENT]}[/INDENT] }
Comment