- Home /
[SOLVED] HUD ammo counter showing up only when a bullet is fired
Hello.
I'm having trouble with the ammo counter I made by following a tutorial on ETeeskiTutorials YouTube channel. The ammo counter only appears when I fire a bullet, then it just disappears again.
So I modified the FPS Tutorial's MachineGun script to show it's ammo. Here is the new part of the script:
function OnGUI () {
if(this.gameObject.active)
{
for (var i : int = 1; i <= bulletsLeft; i++)
{
GUI.DrawTexture(Rect(ammoStartX + ((i - 1) * (ammoSize.x + ammoSpacig)), ammoY, ammoSize.x, ammoSize.y), bulletHudTexture);
}
GUI.Label(ammoCountRect, bulletsLeft.ToString(), clips.ToString());
GUI.DrawTexture(ammoDecorationHudRect, ammoDecorationTexture);
}
}
Well the first thing that comes to $$anonymous$$d is "Is the object active when it isn't firing"?
If you have a script that disables the gun or your particular component when it isn't firing, it would cause your exact problem.
What object did you put this particular behaviour on?
No, the object is active all the time. I put it onto my machine gun game object.
Thank you! I finally found out what's wrong! The script behaves only when fired, I tested it. Thank you! :D