GUI Ammo Count not counting down when I fire

Hi, I’m following a tutorial on how to make GUI’s and HUD’s. The guy who made it missed out an important piece of info. I know how to make the GUI show my initial ammo count (When I pick up the grenades) but when I fire the number won’t lower.

These are the 2 codes I am using
static var GRENADE_AMMO = 0;

function OnControllerColliderHit(hit: ControllerColliderHit)

{

if(hit.gameObject.tag == “crateGrenades”)

{

//destroy the ammo box

Destroy(hit.gameObject);

//add ammo to inventory

GRENADE_AMMO += 8;

print(“YOU NOW HAVE “+ GRENADE_AMMO +” GRENADES!”);

GameObject.Find(“g_Count”).guiText.text = “”+GRENADE_AMMO;

}

}

and then

var speed = 3.0;
var grenadePrefab:Transform;
function Update () {
//finding out if the fire button is pressed
if(Input.GetButtonDown(“Fire1”))
{
if(Collisions.GRENADE_AMMO > 0)
{

//create the prefab
var grenade = Instantiate(grenadePrefab, transform.position, Quaternion.identity);

//add force to prefab
grenade.rigidbody.AddForce(transform.forward * 2000);

Collisions.GRENADE_AMMO --;
print(“YOU NOW HAVE “+ Collisions.GRENADE_AMMO +” GRENADES!”);
}
}
}

What would I need to add to get this to remove 1 count from my GUI? Any help would be appreciated, only just started coding and its taking a bit to get my head around it xD

It seems your using

GameObject.Find(“g_Count”).guiText.text = “”+GRENADE_AMMO;

To update the guitext when you pick up ammo, but then don’t update the text again when you fire a grenade.

btw why are you using COLLISIONS.GRENADE_AMMO > 0 to check if the player has any ammo left? Shouldn’t that be a local variable?

I see what you are trying to do, but it is a bit confusing to read your code. You should format your code better. Select all of your code then hit the binary code button while editing to format everything. Anyhow, I don’t see anything being done as far as GUI goes, just printing. Are you using GUI textures or text? Are these game objects or code generated GUI elements? With that being said, if you are using GUI textures for each grenade icon on the screen just say whenever you throw a grenade, disable the next GUI texture over. To do this you can use an array or just compare the number of remaining grenades to determine what objects should be disabled. I would prefer the latter if you are a beginner.