- Home /
 
 
               Question by 
               GandalfOnTheRun · Dec 14, 2013 at 04:27 PM · 
                guitextguitextammo  
              
 
              Gui text, ammo counter
 var projectile : Rigidbody;
 var speed = 10;
 var ammotext : GUIText;
 var ammo = 75;
 
 function Update () {
 
 if ( Input.GetButtonDown("Fire1")){
 
 clone = Instantiate(projectile, transform.position, transform.rotation);
 clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
 
 Destroy (clone.gameObject, 5);
 
 
 
 }
 
 
 }
 
               Can someone help me. I don't really understand how to get the ammo text to go negative one every time i shoot.
               Comment
              
 
               
               if ( Input.GetButtonDown("Fire1")){
  
 clone = Instantiate(projectile, transform.position, transform.rotation);
 clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
  
 Destroy (clone.gameObject, 5);
 
 ammo -= 1; //here
  
  
  
 }
 
                  I hope that's what you mean.
Also need to insert on line 9:
 ammotext.text = ammo.ToString();
 
                 Answer by RageGolem10 · Dec 14, 2013 at 05:34 PM
Well, if you want to put anything on a GUI, you have to use OnGUI() as a function:
 function OnGUI()
 {
     AmmoGUI.text = "Ammo: " + ammo + "/" + totalAmmo;
 }
 
               As Trollvahkiin said, you have to subtract your ammo everytime you fire, and then after that, call the OnGUI() method to update the GUI Text.
@RageGolem10 - He is using a GUIText, not GUI.Label. You don't manipulate a GUIText inside of OnGUI().
Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Fix Blurry UI text? 10 Answers
Create GUIText from Javascript 3 Answers