GUI Lable

Hey, I made an “ammo” counter for my gun script, how ever it keeps setting it to 100 even though I tell it to become 10, and when I click to Fire the ammo then gets messed up.

Code:

var BulletSpawn : Transform; 
var Bullet : GameObject;
var Ammo = 10 ;

function Start () {

}

function Update () {
if(Input.GetButtonDown("Fire1")) {
Instantiate(Bullet, BulletSpawn.transform.position, BulletSpawn.transform.rotation);
Ammo -- ;
}

}
	function OnGUI () {
		GUI.Label (Rect (10, 10, 100, 20), "Ammo : " + Ammo);
	}

Picture:

Before:
1384069--70618--$0p0RWon.png
After:
1384069--70617--$R8AzKB3.png

Maybe you have 2 gameObjects with that script attached?

Its a public variable
Have you set it to 100 in the inspector?

And as above, it is clearly attached to more than one object (the text looks slightly bold when it’s opverlapping - which happens when theres more than one instance of it running)

Your correct It seems I have it connected to 2 objects, problem is I cant find which it is attached too :c

NVM I used the reference in scene, thanks for your help :smile: