- Home /
 
               Question by 
               PhysicalBeef · Jun 27, 2013 at 08:03 PM · 
                shopneedi  
              
 
              Need help with a shop script.. :/
The problem is, let's say an example:
I have 10 coins. 5 Health costs 5 coins. I have 10/20 health. And when i buy the health, i buy to full, and use all my money.
How can i make it only buy is ONCE? Here's the piece of my code that uses the shop:
 function OnGUI () {
     if(insideEngine == true) {
     GUI.Box (Rect (500,400,100,70), "Press F to\nFix Engine\nCost: 5M");
     if(Input.GetKeyDown("f")) {
             if(Stats.scrapMetal > 5) {
                 if(Stats.shipHealth < 1000) {
                     Stats.scrapMetal -= 5;
                     Stats.shipHealth += 100;
                 }
             }
     }
     }
 }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Julien-Lynge · Jun 27, 2013 at 08:06 PM
OnGUI is called more than once within a frame. Most frames it will be called at least twice, once for each event (read up on GUI events to learn more), where the final event is a repaint event. Each time it's called, the Inputs will be identical. Move your Input check to Update, which is only called once per frame.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                