- Home /
 
Using if/else statements in GUI
HI, I have a GUI script which has a line
if (GUI.Button (Rect (20,70,80,20), "Weapon 2")) {
Target.SelectWeapon(1);
 
                
                
               Then i have another script with a
static var MyScoreCounter : int = 10;
 
                
                
               line. How do I use if/else statements to make the button call out the function Target.SelectWeapon(1); if my MyScoreCounter is more than a certain value, else do nothing?
Answer by Mike 3 · Dec 22, 2010 at 01:10 AM
Use either:
if (GUI.Button (Rect (20,70,80,20), "Weapon 2") && MyScoreCounter > 20) {
    Target.SelectWeapon(1);
}
 
               
               or:
if (GUI.Button (Rect (20,70,80,20), "Weapon 2")) {
    if (MyScoreCounter > 20) {
        Target.SelectWeapon(1);
    }
}
 
               
               depending on how you want to lay it out
thanks for the answer, what can i do to make the points deduct when it has $$anonymous$$yScoreCounter > 20? I'm trying to make something like a shop system.
I mean when $$anonymous$$yScoreCounter > 20, change to the weapon and deduct 20 points from the var?
just add $$anonymous$$yScoreCounter -= 20; below Target.SelectWeapon(1);
Your answer
 
             Follow this Question
Related Questions
Score Counter Help 2 Answers
Lerpz Escapes question 1 Answer
Score/Points when player kills enemy (multiplayer) 1 Answer
Score Help (Im new) 1 Answer
Score display not working 1 Answer