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