Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges