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 Ryanvanpolen · Aug 14, 2014 at 10:02 PM · javascriptguimenudropdownoptions

Dropdown button...

Hi guys... I was working on my main menu, and had to make an drop down button in my options -> interface... My drop-down part is working very well, but I can't select one and the rest of options hide... I was trying to solve the problem for two hours... Help would be fine! Thanks

 #pragma strict
 
 var menuSkin : GUISkin;
 var buttonFontSize : int;
 
 var mainMenu : boolean;
 var start : boolean;
 var upgrades : boolean;
 var battlepedia : boolean;
 var achievements : boolean;
 var options : boolean;
 var extras : boolean;
 var goQuit : boolean;
 
 var editing : boolean;
 
 //toolbar
 var toolbarInt : int = 0;
 var toolbarStrings : String[] = ["Controls", "Interface", "Sound", "Video"];
 
 //interface options
 var Box : Rect;
 var items : String[];
 var selectedItem : String;
 
 var resolutions : String[];
 var selectedResolution : String;
 var resolutionCheck : boolean;
 
 var graphics : String[];
 var selectedGraphic : String;
 var graphicsCheck : boolean;
 
 var subtitles : String[];
 var selectedSubtitles : String;
 var subtitlesCheck : boolean;
 
 var lockCursor : boolean;
 
 private var changeResolution : boolean = false;
 private var changeGraphics : boolean = false;
 private var changeSubtitles : boolean = false;
 
 //sound options
 var masterVolume : int = 80;
 var FXVolume : int = 80;
 var musicVolume : int = 80;
 var VOVolume : int = 80;
 var fidelity : String = "Medium";
 
 function Start () {
 
     mainMenu = true;
     start = false;
     upgrades = false;
     battlepedia = false;
     achievements = false;
     options = false;
     extras = false;
     goQuit = false;
     
     editing = false;
     
     resolutions = ["1024 x 576","1280 x 720","1536 x 864","1792 x 1008","1920 x 1080"];
     selectedResolution = "1280 x 720";
     resolutionCheck = false;
     
     graphics = ["low","medium","good","super","ultra"];
     selectedGraphic = "good";
     graphicsCheck = false;
     
     subtitles = ["none","deutsch","english","français","italiano","nederlands"];
     selectedSubtitles = "none";
     subtitlesCheck = false;
     
     lockCursor = false;
 
 }
 
 function OnGUI () {
 
     GUI.skin = menuSkin;
     
     buttonFontSize = Screen.width / 48;
     buttonFontSize = GUI.skin.button.fontSize;
     
     if (mainMenu) {
     
         if (GUI.Button (Rect (50, Screen.height / 15, Screen.width / 5, Screen.height / 15), "Play")) {
             
             start = true;
             mainMenu = false;
             
         }
         
         if (GUI.Button (Rect (50, Screen.height / 15 * 2.25, Screen.width / 5, Screen.height / 15), "Upgrades")) {
             
             upgrades = true;
             mainMenu = false;
             
         }
         
         if (GUI.Button (Rect (50, Screen.height / 15 * 3.5, Screen.width / 5, Screen.height / 15), "Battlepedia")) {
             
             battlepedia = true;
             mainMenu = false;
             
         }
         
            if (GUI.Button (Rect (50, Screen.height / 15 * 4.75, Screen.width / 5, Screen.height / 15), "Achievements")) {
                
                achievements = true;
                mainMenu = false;
                
            }
     
         if (GUI.Button (Rect (50, Screen.height / 15 * 6, Screen.width / 5, Screen.height / 15), "Options")) {
             
             options = true;
             mainMenu = false;
             
         }
         
         if (GUI.Button (Rect (50, Screen.height / 15 * 7.25, Screen.width / 5, Screen.height / 15), "Extras")) {
             
             extras = true;
             mainMenu = false;
             
         }
         
         if (GUI.Button (Rect (50, Screen.height / 15 * 8.5, Screen.width / 5, Screen.height / 15), "Quit")) {
             
             goQuit = true;
             mainMenu = false;
             
         }
     }
     
     var windowSize : Rect = Rect (0, 0, Screen.width, Screen.height);
     var startWindowSize : Rect = Rect (Screen.width / 2 - 480, Screen.height / 2 - 270, 960, 540);;
     var optionsWindowSize : Rect = Rect (Screen.width / 2 - 480, Screen.height / 2 - 270, 960, 540);
     var quitWindowSize : Rect = Rect (Screen.width / 2 - 455, Screen.height / 2 - 100, 910, 170);
     
     if (start) {
     
         startWindowSize = GUI.Window (0, startWindowSize, PlayWindow, "Play");
             
     }
     
     if (upgrades) {
     
         windowSize = GUI.Window (3, windowSize, UpgradesWindow, "Upgrades");
     
     }
     
     if (battlepedia) {
     
         windowSize = GUI.Window (6, windowSize, BattlepediaWindow, "Battlepedia");
             
     }
     
     if (achievements) {
     
         windowSize = GUI.Window (7, windowSize, AchievementsWindow, "Achievements");
             
     }
     
     if (options) {
     
         optionsWindowSize = GUI.Window (8, optionsWindowSize, OptionsWindow, "Options");
             
     }
 
     if (extras) {
     
         windowSize = GUI.Window (9, windowSize, ExtrasWindow, "Extras");
             
     }
                     
     if(goQuit) {
         
         quitWindowSize = GUI.Window (10, quitWindowSize, QuitWindow, "Are you sure you want to quit?");
         
         
     }    
 }
 
 function PlayWindow (id : int) {
     
     //Campaign, skirmish, multiplayer
 
 }
 
 function UpgradesWindow (id : int) {
     
     //battlepedia
 
 }
 
 function BattlepediaWindow (id : int) {
     
     //battlepedia
 
 }
 
 function AchievementsWindow (id : int) {
     
     //Achievements
 
 }
 
 function OptionsWindow (id : int) {
 
     toolbarInt = GUI.Toolbar(Rect(10, 35, 940, 50), toolbarInt, toolbarStrings);
     
     if (toolbarInt == 0) {
         //diplay controls options
         GUI.Label(Rect (50, 110, 400, 30), "Zoom sensitivity");
         
     } else if (toolbarInt == 1) {
         //display interface options
         GUI.Label(Rect (50, 110, 400, 30), "Resolution");
         
         if (GUI.Button(Rect(250, 100, 235, 50), selectedResolution)) {
             resolutionCheck = true;
             Box = Rect(250, 100, 235, 50);
             items = resolutions;
             selectedItem = selectedResolution;
             changeResolution = editing;
             editing = true;
         }
         
         if (changeResolution) {
             Dropdown();
         }
         
     } else if (toolbarInt == 2) {
         //display sound options
         GUI.Label(Rect (50, 110, 400, 30), "Master volume");
         GUI.Label(Rect (860, 110, 400, 30), masterVolume + "%");
         masterVolume = GUI.HorizontalSlider (Rect (350, 120, 500, 30), masterVolume, 0, 100);
         GUI.Label(Rect (50, 150, 400, 30), "FX volume");
         GUI.Label(Rect (860, 150, 400, 30), FXVolume + "%");
         FXVolume = GUI.HorizontalSlider (Rect (350, 160, 500, 30), FXVolume, 0, 100);
         GUI.Label(Rect (50, 190, 400, 30), "Music volume");
         GUI.Label(Rect (860, 190, 400, 30), musicVolume + "%");
         musicVolume = GUI.HorizontalSlider (Rect (350, 200, 500, 30), musicVolume, 0, 100);
         GUI.Label(Rect (50, 230, 400, 30), "VO volume");
         GUI.Label(Rect (860, 230, 400, 30), VOVolume + "%");
         VOVolume = GUI.HorizontalSlider (Rect (350, 240, 500, 30), VOVolume, 0, 100);
         
     } else if (toolbarInt == 3) {
         //display video options
     }
     
     if (GUI.Button (Rect (10, 480, 235, 50), "Cancel")) {
         
         //cancel...
         options = false;
         mainMenu = true;
         
     }
     
     if (GUI.Button (Rect (372.5, 480, 235, 50), "Default")) {
         
         //reset every option
         options = false;
         mainMenu = true;
         
     }
     
     if (GUI.Button (Rect (715, 480, 235, 50), "Apply")) {
         
         //save these options first!!
         options = false;
         mainMenu = true;
         
     }
 
 }
 
 function ExtrasWindow (id : int) {
 
     //Extras
     
 }
 
 function QuitWindow (id : int) {
     
     if (GUI.Button (Rect (70, 50, 350, 80), "Yes")) {
         Application.Quit();
     }
             
     if (GUI.Button (Rect (490, 50, 350, 80), "No")) {
         goQuit = false;
         mainMenu = true;
     }
 
 }
 
 function Dropdown () {
     
     for (var x : int = 0; x < items.Length; x++) {
         if (GUI.Button(Rect(Box.x, (Box.height * x) + Box.y + Box.height, Box.width, Box.height), items[x])) {
             selectedItem = items[x];
             
             if (resolutionCheck) {
                 selectedItem = selectedResolution;
             } else if (graphicsCheck) {
                 selectedItem = selectedGraphic;
             } else if (subtitlesCheck) {
                 selectedItem = selectedSubtitles;
             }
             
             editing = 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

0 Replies

· Add your reply
  • Sort: 

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

1 Person is following this question.

avatar image

Related Questions

How to use options in the Dropdown menu UI? 2 Answers

Stat bars in Menu system? 1 Answer

Setting Scroll View Width GUILayout 1 Answer

Web player screen resolution GUI placement 1 Answer

Horizontal Slider with Labels 3 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