x


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?

more ▼

asked Dec 22 '10 at 01:02 AM

user-3061 (yahoo) gravatar image

user-3061 (yahoo)
126 29 29 37

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Dec 22 '10 at 01:10 AM

Mike 3 gravatar image

Mike 3
30.5k 10 65 252

thanks for the answer, what can i do to make the points deduct when it has MyScoreCounter > 20? I'm trying to make something like a shop system.

Dec 22 '10 at 01:32 AM user-3061 (yahoo)

I mean when MyScoreCounter > 20, change to the weapon and deduct 20 points from the var?

Dec 22 '10 at 01:33 AM user-3061 (yahoo)

just add MyScoreCounter -= 20; below Target.SelectWeapon(1);

Dec 22 '10 at 01:59 AM Mike 3

thanks for the help!

Dec 22 '10 at 03:42 AM user-3061 (yahoo)
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3669
x272
x217
x75
x16

asked: Dec 22 '10 at 01:02 AM

Seen: 1883 times

Last Updated: Dec 22 '10 at 01:02 AM