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 omnirusted · Sep 25, 2013 at 06:01 PM · buildbuttonmenumultiplerts

Multiple functions in a single button not working

I'm attempting to make a build menu, RTS style, in which several buttons with graphics appear when you right-click, then you click one of those buttons, it prints the button's name, then turns the build menu off.

So far I have gotten the build menu to turn on with right click, show the buttons in their proper places, assign textures to those buttons, have the build menu turn off when I right click, make the window dragable... but when I click one of the buttons nothing happens.

What exactly am I doing wrong here? The button code worked just fine until I put buildMenuOn = false; in there.

(Yes, this is designed to have 2 rows of 4 buttons each. I haven't yet made textures or assigned the other buttons yet, and only have 3 so far.)

 #pragma strict
 
 var buildMenuOn : boolean;
 var buildRect : Rect = Rect (20,20,235,300);
 
 // Textures for the buttons
 var buttLivingQuarters : Texture;
 var buttCafeteria : Texture;
 var buttMedical : Texture;
 
 function Start () 
 {
 var buildMenuOn = false; // the build menu starts out off
 }
 
 function Update () 
 {
     if (Input.GetButtonDown("Fire2")) // if right mouse button is clicked
     {
         if(buildMenuOn) // if the build menu is visible
         {
             buildMenuOn = false; // turn it off
         }
         else // if the build menu is not on
         {
             OnGUI(); // bring up the build menu GUI
             buildMenuOn = true; // turn the build menu on
         }
     }
 }
 
 
 
 function OnGUI()
 {
     if(buildMenuOn)
     {
             buildRect = GUI.Window(0,buildRect,BuildWindow,"Please select your Prefab");
     }
 }
 
 function BuildWindow(windowID: int)
 {
         // Draggable Windows
         GUI.DragWindow(Rect(0,0,10000,10000));
         
         //build button controls
         
         // top line
         if (GUI.Button(Rect(10,20,50,50),buttLivingQuarters))
         {
             print("Living Quarters");
             buildMenuOn = false;
         }
         
         if (GUI.Button(Rect(65,20,50,50),buttMedical))
         {
             print("Medical");
             buildMenuOn = false;
         }
         
         if (GUI.Button(Rect(120,20,50,50),buttLivingQuarters))
         {
             print("Living Quarters");
             buildMenuOn = false;
         }
         
         if (GUI.Button(Rect(175,20,50,50),buttLivingQuarters))
         {
             print("Living Quarters");
             buildMenuOn = false;
         }
         
         
         //second line
         if (GUI.Button(Rect(10,75,50,50),buttCafeteria))
         {
             print("Living Quarters");
             buildMenuOn = false;
         }
         
         if (GUI.Button(Rect(65,75,50,50),buttCafeteria))
         {
             print("Living Quarters");
             buildMenuOn = false;
         }
         
         if (GUI.Button(Rect(120,75,50,50),buttCafeteria))
         {
             print("Living Quarters");
             buildMenuOn = false;
         }
         
         if (GUI.Button(Rect(175,75,50,50),buttCafeteria))
         {
             print("Living Quarters");
             buildMenuOn = false;
         }
 }
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
1
Best Answer

Answer by ArkaneX · Sep 25, 2013 at 07:00 PM

Please move this line

 GUI.DragWindow(Rect(0,0,10000,10000));

to the end of OnGUI method. This should fix it.

Additionally, you don't have to explicitly call OnGUI (and besides, currently calling it does nothing, as it is called when buildMenuOn is still false). So I suggest changing the code of your right mouse button test to:

 if (Input.GetButtonDown("Fire2")) // if right mouse button is clicked
 {
     buildMenuOn = !buildMenuOn;
 }
Comment
Add comment · Show 5 · 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 omnirusted · Sep 25, 2013 at 07:43 PM 0
Share

Thanks for the quick answer!

It was really that simple of an answer? Well, don't I feel silly. I actually stared at that for a while wondering.

As for the !build$$anonymous$$enuOn, what exactly does that do? I haven't seen any tutorials or script using the ! yet. Is that for Java or C#?

avatar image ArkaneX · Sep 25, 2013 at 08:22 PM 0
Share

Converted your answer to a comment (please post only real answer as answers).

! sign is unary logical negation operator (equivalent of NOT). It returns true if its operand is false, or false if its operand is true. Works in both C# and JavaScript.

As a side note - if an answer helped, please accept it using an icon at its top, under upvote/downvote icons. This way users here gain karma (or you can say experience, like in RPG) :)

avatar image omnirusted · Sep 25, 2013 at 09:41 PM 0
Share

New to the way this is done. Have to have 15 rep to use the arrow first. Thanks for your help though, you've been seriously helpful.

avatar image ArkaneX · Sep 25, 2013 at 10:30 PM 0
Share

15 karma is required to upvote, but all users can accept answers to their own questions. It's the third icon.

avatar image omnirusted · Sep 26, 2013 at 02:29 AM 0
Share

Done! Thanks again!

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

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Button doesn't work after build 1 Answer

Distribute terrain in zones 3 Answers

Button Animation Bug 1 Answer

How do you make a Main Menu that only takes Joystick input and is not affected by the Cursor 2 Answers

How to make Iphone Menu-Unity 2 Answers


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