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 sriram90 · Aug 26, 2011 at 08:47 AM · guiwindow

GUI Window problem

Hi all,

i have worked with unity before six months. but am trying and working with GUI windows. it's giving trouble to me about 2 hours. here is my code

 using UnityEngine;
 using System.Collections;
 
 public class Menu : MonoBehaviour {
     
     public GUIStyle background = new GUIStyle();
     private bool menus = true;
     public Rect window1 = new Rect(3,3,Screen.width-3,Screen.height-3);
     
     void OnGUI()
     {
         GUI.Label(new Rect(0,0,Screen.width,Screen.height)," ",background);    
         
         if(menus)
         {
             if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2-60,100,30),"Play Game"))
             {
                 Application.LoadLevel(1);
             }
         
             else if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2-20,100,30),"Settings"))
             {
                 window1 = GUI.Window(1,window1,settingsWindow,"");
                 menus = false;
             }
         
             else if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2+20,100,30),"Credits"))
             {
                 
             }
         }
     }
     
     void settingsWindow(int windowID)
     {
         GUI.Label(new Rect(50,50,100,30),"Volume");
     }
 }

i have worked before in the same thing. here the problem is the new window is not opening. can any one say what am doing wrong?? Thank you in advance.

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

2 Replies

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

Answer by sriram90 · Sep 02, 2011 at 12:11 PM

I have called the window directly when click on button in my question. thats not the correct way. here we need to set a boolean value for that,if it is correct we need to open the window.

here is the correct code....

 using UnityEngine;
 using System.Collections;
 
 public class Menu : MonoBehaviour {
 
     public GUIStyle background = new GUIStyle();
     private bool menus = true;
     private bool settingsWin = false;
     public Rect window1 = new Rect(3,3,Screen.width-3,Screen.height-3);
 
     void OnGUI()
     {
         GUI.Label(new Rect(0,0,Screen.width,Screen.height)," ",background); 
 
         if(menus)
         {
             if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2-60,100,30),"Play Game"))
             {
                 Application.LoadLevel(1);
             }
 
             else if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2-20,100,30),"Settings"))
             {
                 settingsWin = true;
                 menus = false;
             }
 
             else if(GUI.Button(new Rect((Screen.width)/2-50,(Screen.height)/2+20,100,30),"Credits"))
             {
 
             }
         }
         if(settingsWin)
         {
            window1 = GUI.Window(1,window1,settingsWindow,"");
         }
 
     }
 
     void settingsWindow(int windowID)
     {
         GUI.Label(new Rect(50,50,100,30),"Volume");
     }
 }
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
avatar image
0

Answer by Jorn · Aug 27, 2011 at 04:35 PM

The problem here is that you call the settingsWindow function ones. After setting the menus boolean to false, the function never gets called again, therefore is never drawn on the screen again.

Comment
Add comment · Show 1 · 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 sriram90 · Aug 29, 2011 at 03:22 AM 0
Share

ya here we need to set a boolean value....we have to check if it is true means the window get open...

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Gui in Gui Not Working ? 1 Answer

GUI Button sound problem, don´t work 1 Answer

What's a great way to make a custom information window pop up 1 Answer

GUI Rotation 1 Answer

How to make multiple GUI window? 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