Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 spiralfire11 · Oct 06, 2015 at 02:09 PM · c#guibuttontoolbarguiwindow

GUI.Window not displaying Buttons

  • UPDATE : I've updated the script once again. Also, I tested a few things, and I put the hSlider right under where I define what the selectedToolbar is. It appeared when it was there... Any ideas?

    using UnityEngine; using System.Collections;

    public class Options : MonoBehaviour {

       private Rect windowRect = new Rect(200, 200, 1200, 500);
         private int selectedToolbar = 0;
         private string[] toolbarStrings = { "Quality", "Sound", "Game Size", "Menu" };
         public float hSliderValue = 0.0f;
         private bool IsOptionsAvailable = false;
         private int MyCurrentRes;
     
         void Start()
         {
            
         }
     
         void Update()
         {
             if (Input.GetKeyDown(KeyCode.O) && IsOptionsAvailable == false)
             {
                 IsOptionsAvailable = true;
                 Debug.Log ("Show Options");
             }
             else if (Input.GetKeyDown(KeyCode.O) && IsOptionsAvailable == true) 
             {
                 IsOptionsAvailable = false;
                 Debug.Log("Hide Options");
             }
     
         }
     
         void OnGUI()
         {
             if (IsOptionsAvailable)
             {
                 windowRect = GUI.Window(0, windowRect, WindowFunction, "Options");
             }
         }
     
         void WindowFunction(int windowID)
         {
             GUILayout.BeginHorizontal();
             selectedToolbar = GUILayout.Toolbar(selectedToolbar, toolbarStrings);
             
             if (GUI.changed)
             {
                 Debug.Log("Toolbar was clicked");
     
                     if (selectedToolbar == 0)
                     {
                         Debug.Log("Graphics selected");
                         GUILayout.BeginVertical();
                         string[] names = QualitySettings.names;
                         int i = 0;
                         while (i < names.Length)
                         {
                             if (GUILayout.Button(names[i]))
                                 QualitySettings.SetQualityLevel(i, true);
     
                             i++;
                         }
                         GUILayout.EndVertical();
                     }
     
                     if (selectedToolbar == 2)
                     {
                         GUILayout.BeginVertical();
                         Debug.Log("Game size selected");
                         if (GUILayout.Button("Fullscreen Mode"))
                         {
                             MyCurrentRes = QualitySettings.GetQualityLevel();
                             Screen.SetResolution(1680, 1050, true);
                             QualitySettings.currentLevel = QualityLevel.Fantastic;
                             QualitySettings.SetQualityLevel(MyCurrentRes, true);
                             Debug.Log("Fullscreen");
                         }
                         else if (GUILayout.Button("Window Mode"))
                         {
                             MyCurrentRes = QualitySettings.GetQualityLevel();
                             Screen.fullScreen = false;
                             QualitySettings.currentLevel = QualityLevel.Fantastic;
                             QualitySettings.SetQualityLevel(MyCurrentRes, true);
                             Debug.Log("Window");
                         }
                         Resolution[] resolutions = Screen.resolutions;
                         foreach (Resolution res in Screen.resolutions)
                         {
                             if (GUILayout.Button(res.width.ToString() + " x " + res.height.ToString()))
                             {
                                 MyCurrentRes = QualitySettings.GetQualityLevel();
                                 Screen.SetResolution(res.width, res.height, false);
                                 QualitySettings.currentLevel = QualityLevel.Fantastic;
                                 QualitySettings.SetQualityLevel(MyCurrentRes, true);
                                 Debug.Log(res.width.ToString() + " x " + res.height.ToString());
                             }
                         }
                         GUILayout.EndVertical();
                     }
                     if (selectedToolbar == 3)
                     {
                         Debug.Log("Go to Main Menu");
                         Application.LoadLevel("MainMenu");
                     }
     
                     if (selectedToolbar == 1)
                     {
                         Debug.Log("Change Volume");
                         GUI.Box(new Rect(140, 140, 200, 50), "Volume");
                         hSliderValue = GUI.HorizontalSlider(new Rect(40, 40, 600, 200), hSliderValue, 0.0f, 10.0f);
                         AudioListener.volume = hSliderValue;
                     }
                 }
             GUILayout.EndHorizontal();
                 GUI.DragWindow();
         }
     }
    
    

//OLD Question :I have a script that permits me to change the runtime qualitysettings and screen resolution. However, whenever I build the game, sometimes when I change the resolution the screen becomes black, or the camera gets uncalibrated (and mouse) and i have to select another quality setting to calibrate it. Any suggestions what this might be?

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
0
Best Answer

Answer by spiralfire11 · Jan 19, 2016 at 07:15 PM

I fixed the problem, just completely re-arranged my script without the usage of a toolbar :

 using UnityEngine; using System.Collections;
 
 public class Options : MonoBehaviour { //Les options de GUI utilisent tous les commandes de UnirtEngine.GUI;
     private Rect windowRect = new Rect(Screen.width*0.2f, Screen.height*0.2f, 1200, 600);
     private int selectedToolbar = 0;
     public float hSliderValue = 0.0f;
     private bool IsOptionsAvailable = false;
     private int MyCurrentRes;
     private float MyCurrentSound;
     private Color guiColor;
 
     void Start()//On vas chercher les components comme le son afin de pouvoir le changer
     {
         hSliderValue = AudioListener.volume;
         guiColor = GUI.color;
     }
 
     void Update()// Si on tappe la touche O opur options, on vas pouvoir ouvrir le menu d'options
     {
         if (Input.GetKeyDown(KeyCode.O) && IsOptionsAvailable == false)
         {
             IsOptionsAvailable = true;
             Debug.Log ("Show Options");
         }
         else if (Input.GetKeyDown(KeyCode.O) && IsOptionsAvailable == true) 
         {
             IsOptionsAvailable = false;
             Debug.Log("Hide Options");
         }
     }
 
     void OnGUI()
     {
         if (IsOptionsAvailable)
         {
             windowRect = GUI.Window(0, windowRect, WindowFunction, "Options");
         }
     }
 
     void WindowFunction(int windowID)
     {
         GUILayout.BeginArea(new Rect(10, 10, 250, windowRect.height));// On commence une section qui nous permet de changer la qualité du jeux
                     GUILayout.BeginVertical();
         GUILayout.Button("Graphics");
         GUI.backgroundColor = Color.green;
         string[] names = QualitySettings.names;
                     int i = 0;
                     while (i < names.Length)
                     {
                         if (GUILayout.Button(names[i]))
                             QualitySettings.SetQualityLevel(i, true);
 
                         i++;
                     }
                     GUILayout.EndVertical();
         GUILayout.EndArea();
 
         GUILayout.BeginArea(new Rect(265, 10, 250, windowRect.height));// On commence une section qui nous permet de changer la résolution du jeux
         GUILayout.BeginVertical();
         GUI.backgroundColor = guiColor;
         GUILayout.Button("Game Size");
 
         GUI.backgroundColor = Color.red;
         if (GUILayout.Button("Fullscreen Mode"))
                     {
                         MyCurrentRes = QualitySettings.GetQualityLevel();
                         QualitySettings.SetQualityLevel(6, true);
                         Screen.SetResolution(1680, 1050, true);
                         QualitySettings.SetQualityLevel(MyCurrentRes, true);
                         Debug.Log("Fullscreen");
                     }
                     else if (GUILayout.Button("Window Mode"))
                     {
                         MyCurrentRes = QualitySettings.GetQualityLevel();
                         QualitySettings.SetQualityLevel(6, true);
                         Screen.fullScreen = false;
                         QualitySettings.SetQualityLevel(MyCurrentRes, true);
                         Debug.Log("Window");
                     }
                     Resolution[] resolutions = Screen.resolutions;
                     foreach (Resolution res in Screen.resolutions)
                     {
                         if (GUILayout.Button(res.width.ToString()
 + " x " + res.height.ToString()))
                         {
                             MyCurrentRes = QualitySettings.GetQualityLevel();
                             QualitySettings.SetQualityLevel(6, true);
                             Screen.SetResolution(res.width, res.height, false);
                             QualitySettings.SetQualityLevel(MyCurrentRes, true);
                             Debug.Log(res.width.ToString() + " x "
 + res.height.ToString());
                         }
                     }
                     GUILayout.EndVertical();
         GUILayout.EndArea();
 
         GUILayout.BeginArea(new Rect(520, 10, 250, windowRect.height));// On commence une section qui nous permet de retourner au menu/recommencer le jeux *PAS RECOMMENDER*
         GUILayout.BeginVertical();
         GUI.backgroundColor = guiColor;
         if (GUILayout.Button("Go to Menu"))
                 {
                     Application.LoadLevel("OpeningMenu");
                 }
         if (GUILayout.Button("Restart Game"))
                 {
                     Application.LoadLevel(0);
                 }
 
 
       
 
         GUILayout.EndVertical();
         GUILayout.EndArea();
 
         GUILayout.BeginArea(new Rect(775, 10, 250, windowRect.height));
                     GUILayout.BeginVertical();
         
                     GUILayout.Button("Volume");
         GUI.backgroundColor = Color.blue;
         hSliderValue = GUILayout.HorizontalSlider(hSliderValue,
 0.0f, 10.0f); // On commence une section qui nous permet de changer le volume
                     GUILayout.EndVertical();
                     
                     AudioListener.volume = hSliderValue;
         GUILayout.EndArea();
 
             GUI.DragWindow();
     } }



Comment
Add comment · 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

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

28 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 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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer

If health = 0, show a GUI.button C# 2 Answers

In game Escape menu displays all the time 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