• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by user-3061 (yahoo) · Dec 22, 2010 at 01:02 AM · guiscoreif-statementsweaponif-else

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image user-3061 (yahoo) · Dec 22, 2010 at 01:32 AM 0
Share

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.

avatar image user-3061 (yahoo) · Dec 22, 2010 at 01:33 AM 0
Share

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

avatar image Mike 3 · Dec 22, 2010 at 01:59 AM 0
Share

just add $$anonymous$$yScoreCounter -= 20; below Target.SelectWeapon(1);

avatar image user-3061 (yahoo) · Dec 22, 2010 at 03:42 AM 0
Share

thanks for the help!

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Score/Points when player kills enemy (multiplayer) 1 Answer

Score Help (Im new) 1 Answer

error CS0103: The name `wing' does not exist in the current context 2 Answers

Unity ignoring if statement for high score 2 Answers

Score display not working 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges