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
-1
Question by LT23Live · Feb 19, 2014 at 12:21 AM · disableenablegui-buttongui-window

How to enable/disable (hide and unhide) GUI.Windows

Hello Unity Answers!

The title says it all. I am trying to hide and unhide my GUI.Windows with the click of a GUI.Button.

I hope you all can help. I am attaching my current script as a example. Relevant lines are (lines 110 - 112) (161 +)

Thanks for your help everyone!

`using UnityEngine; using System.Collections;

public class MainMenu : MonoBehaviour {

 public Texture2D Next;
 public Texture2D NextRollOver;
 public string NextlevelToLoad;

 public Texture2D Back;
 public Texture2D BackRollover;
 public string BacklevelToLoad;
 
 //Race
 private bool humanButton;
 public Texture2D Human;
 public Texture2D HumanRollOver;

 private bool centaurButton;
 public Texture2D Centaur;
 public Texture2D CentaurRollOver;

 private bool demonButton;
 public Texture2D Demon;
 public Texture2D DemonRollOver;

 private bool maleButton;
 public Texture2D Male;
 public Texture2D MaleRollOver;

 private bool femaleButton;
 public Texture2D Female; 
 public Texture2D FemaleRollOver;
 
 
 public GameObject spawn;
 
 public GameObject humanMale;
 public GameObject humanFemale;
 public GameObject centaurMale;
 public GameObject centaurFemale;
 public GameObject demonMale;
 public GameObject demonFemale;
 
 private bool raceNextButton;

 //Class
 private bool warriorButton;
 public Texture2D Warrior;
 public Texture2D WarriorRollOver;

 private bool fireMageButton;
 public Texture2D FireMage;
 public Texture2D FireMageRollOver;

 private bool rogueButton;
 public Texture2D Rogue;
 public Texture2D RogueRollOver;

 private bool iceMageButton;
 public Texture2D IceMage;
 public Texture2D IceMageRollOver;

 private bool beastMasterButton;
 public Texture2D BeastMaster;
 public Texture2D BeastMasterRollOver;

 private bool ClassBack ;
 private bool ClassNext ;

 //Stats 
 private int [] stats = new int[] {5,5,5,5,5,5};
 private int pointSpend = 25; 
 private GUIText points;
 
 private GUIText strength;
 public Texture2D strengthSpend;
 public Texture2D strengthReturn;
 
 private GUIText stamina;
 public Texture2D staminaSpend;
 public Texture2D staminaReturn;

 private GUIText constitution;
 public Texture2D constitutionSpend;
 public Texture2D constitutionReturn;
 
 private GUIText agility;
 public Texture2D agilitySpend;
 public Texture2D agilityReturn;
 
 private GUIText intellegence;
 public Texture2D intelligenceSpend;
 public Texture2D intellegenceReturn;
 
 private GUIText willpower; 
 public Texture2D willpowerSpend;
 public Texture2D willpowerReturn;

 private bool statsBack ;
 private bool statsNext ;

 private string name;
 
 // Setup 

 public GameObject scribe;

 private Rect WindowRect0 = new Rect( 270 , 80, 600 , 800);
 private Rect WindowRect1 = new Rect( 270 , 80, 600 , 800);
 private Rect WindowRect2 = new Rect (270 , 80, 600 , 800);


 //private int windowID = 0;


 void Start(){
     OnGUI ();

     humanButton = true;
     centaurButton = false;
     demonButton = false;
     maleButton = true;
     femaleButton = false;
     raceNextButton = false;

     warriorButton = false;
     rogueButton = false; 
     beastMasterButton = false;
     iceMageButton = false;
     fireMageButton = false; 
     ClassBack = true;
     ClassNext = false;

     statsBack = true;
     statsNext = false; 



     }t

 void Update(){
     points.text = pointSpend.ToString (); 
     strength.text = stats [0].ToString ();
     stamina.text = stats [1].ToString ();
     constitution.text = stats [2].ToString ();
     agility.text = stats [3].ToString ();
     intellegence.text = stats [4].ToString ();
     willpower.text = stats [5].ToString ();

     
     if ((warriorButton) & (rogueButton) &(beastMasterButton) & (iceMageButton) & (fireMageButton)){
         ClassNext = false;
     }

 }



 void OnGUI(){
             
     WindowRect0 = GUI.Window (0, WindowRect0, DoMyWindow, "Race");
     WindowRect1 = GUI.Window (1, WindowRect1, DoMyWindow, "Class");
     WindowRect2 = GUI.Window (2, WindowRect2, DoMyWindow, "Stats");

 }
 
 
 void DoMyWindow (int windowID) {
     
     if (windowID == 0) {
         
         if (maleButton = GUI.Button (new Rect (90, 40, 100, 100), Male)) {
             print ("Got a click 'Male' in window" + windowID);
             if (maleButton == true) {
                 maleButton = false;
                 print ("Male = false");
             } 
             if (maleButton == false) {
                 maleButton = true;
                 print ("Male = True");
             }
         }
         
         if (femaleButton = GUI.Button (new Rect (390, 40, 100, 100), Female)) {
             print ("Got a click 'Female' in window" + windowID);
             if (femaleButton == true) {
                 femaleButton = false;
                 print ("Female = false");
             } 
             if (femaleButton == false) {
                 femaleButton = true;
                 print ("Female = True");
             }
         }
         
         if (humanButton = GUI.Button (new Rect (90, 150, 400, 110), Human)) {
             print ("Got a click in window" + windowID);
             if (humanButton == true) {
                 humanButton = false;
                 print ("human = false");
             } 
             if (humanButton == false) {
                 humanButton = true;
                 print ("human = True");
             }
         }
         
         if (centaurButton = GUI.Button (new Rect (90, 270, 400, 110), Centaur)) {
             print ("Got a click in window" + windowID);
             if (centaurButton == true) {
                 centaurButton = false;
                 print ("centar = false");
             } 
             if (centaurButton == false) {
                 centaurButton = true;
                 print ("centaur = True");
             }
         }
         
         if (demonButton = GUI.Button (new Rect (90, 390, 400, 110), Demon)) {
             print ("Got a click in window" + windowID);
             if (demonButton == true) {
                 demonButton = false;
                 print ("demon = false");
             }
             if (demonButton == false) {
                 demonButton = true;
                 print ("demon = True");
             }
         }
         
         if (GUI.Button (new Rect (40, 650, 100, 100), Back)) {
             print ("Got a click in window" + windowID);
             Application.LoadLevel (BacklevelToLoad);
         }
         
         if (raceNextButton = GUI.Button (new Rect (440, 650, 100, 100), Next)) {
             print ("Got a click in window" + windowID);
         }
     } 


     else if (windowID == 1) {


                     if (GUI.Button (new Rect (90, 150, 400, 110), Warrior))
                             print ("Got a click in window" + windowID);
         
                     if (GUI.Button (new Rect (90, 270, 400, 110), Rogue))
                             print ("Got a click in window" + windowID);
         
                     if (GUI.Button (new Rect (90, 390, 400, 110), BeastMaster))
                             print ("Got a click in window" + windowID);

                     if (GUI.Button (new Rect (90, 510, 400, 110), FireMage))
                             print ("Got a click in window" + windowID);
         
                     if (GUI.Button (new Rect (90, 630, 400, 110), IceMage))
                             print ("Got a click in window" + windowID);
         
                     if (GUI.Button (new Rect (40, 650, 100, 100), Back))
                             print ("Got a click in window" + windowID);
         
                     if (GUI.Button (new Rect (440, 650, 100, 100), Next)) {
                             print ("Got a click in window" + windowID);

                     }
             }


     else if (windowID == 2) {


         GUI.Label (new Rect ( 90 , 90 , 120, 50), "Strength");
         GUI.Label (new Rect ( 90, 150, 120, 50), "Stamina") ;
         GUI.Label (new Rect ( 90, 210 , 120, 50), "Agility");
         GUI.Label (new Rect ( 90, 270, 120, 50), "Constitution");
         GUI.Label (new Rect ( 90, 330, 120, 50), "Intelligence");
         GUI.Label (new Rect ( 90, 390, 120, 50), "Willpower");

         if (GUI.Button (new Rect ( 240, 90, 50, 50), strengthReturn)){
             print ("Got a click in window" + windowID);
             if (stats[0]>= 5){
                 stats[0] = stats[0] - 1;
             }
         }
         
         if( GUI.Button (new Rect ( 240, 150, 50, 50), staminaReturn)){
             print ("Got a click in window" + windowID);
         if (stats[1]>= 5){
             stats[1] = stats[1] - 1;
         }
     }

     
         if (GUI.Button ( new Rect ( 240, 210, 50, 50) , agilityReturn)){
             print ("Got a click in window" + windowID);
             if (stats[2]>= 5){
                 stats[2] = stats[2] - 1;
             }
         }

         if (GUI.Button (new Rect (240, 270, 50, 50), constitutionReturn)){
             print ("Got a click in window" + windowID);
             if (stats[3]>= 5){
                 stats[3] = stats[3] - 1;
             }
         }

         if (GUI.Button (new Rect (240, 330, 50,50), intellegenceReturn)){
             print ("Got a click in window" + windowID);
             if (stats[4]>= 5){
                 stats[4] = stats[4] - 1;
             }
         }

         if (GUI.Button (new Rect ( 240, 390, 50, 50), willpowerReturn)){
             print ("Got a click in window" + windowID);
             if (stats[5]>= 5){
                 stats[5] = stats[5] - 1;
             }
         }

         
         GUI.Label (new Rect ( 320, 90 , 50, 50),  stats [0].ToString());
         GUI.Label (new Rect ( 320, 150 , 50, 50), stats [1].ToString());
         GUI.Label (new Rect ( 320, 210 , 50, 50), stats [2].ToString());
         GUI.Label (new Rect ( 320, 270 , 50, 50), stats [3].ToString());
         GUI.Label (new Rect ( 320, 330 , 50, 50), stats [4].ToString());
         GUI.Label (new Rect ( 320, 390 , 50, 50), stats [5].ToString());

         if (GUI.Button (new Rect (360, 90, 50, 50), strengthSpend)){
             print ("Got a click in window" + windowID);
             if (stats[0]<= 5){
                 stats[0] = stats[0] + 1;
             }
         }

         if (GUI.Button (new Rect (360, 150, 50, 50), staminaSpend)){
             print ("Got a click in window" + windowID);
             if (stats[1]<= 5){
                 stats[1] = stats[1] + 1;
             }
         }

         if (GUI.Button (new Rect (360, 210, 50, 50), agilitySpend)){
             print ("Got a click in window" + windowID);
             if (stats[2]<= 5){
                 stats[2] = stats[2] + 1;
             }
         }

         if (GUI.Button (new Rect (360, 270, 50, 50), constitutionSpend)){
             print ("Got a click in window" + windowID);
             if (stats[3]<= 5){
                 stats[3] = stats[3] + 1;
             }
         }

         if (GUI.Button (new Rect (360, 330, 50,50), intelligenceSpend)){
             print ("Got a click in window" + windowID);
             if (stats[4]<= 5){
                 stats[4] = stats[4] + 1;
             }
         }

         if (GUI.Button (new Rect (360, 390, 50, 50), willpowerSpend)){
             print ("Got a click in window" + windowID);
             if (stats[5]<= 5){
                 stats[5] = stats[5] + 1;
             }
         }

         if (GUI.Button (new Rect (40, 650, 100, 100), Back)){
             print ("Got a click in window" + windowID);
             }

         if (statsNext = GUI.Button (new Rect (440, 650, 100, 100), Next)){
             print ("Got a click in window" + windowID);
                 if (statsNext == true){
                 Application.LoadLevel (NextlevelToLoad);
             }
         }
         GUI.Label (new Rect ( 220, 600, 200, 20),"Name");
         GUI.TextField (new Rect ( 200, 650, 300, 20), name, 50 );
         }
     }

     void OnMouseUp(){

         if (maleButton == true) {
                 femaleButton = false;
         }
             
         if (femaleButton == true) {
                 maleButton = false;
         }
             
         if (humanButton == true) {
                 centaurButton = false;
                 demonButton = false;
         }
             
         if (centaurButton == true) {
                 humanButton = false;
                 demonButton = false;
         }
             
         if (demonButton == true) {
                 humanButton = false;
                 centaurButton = false;
         }
             
         if ((humanButton == true) & (maleButton == true)) {
                 Instantiate (humanMale, spawn.transform.position, Quaternion.identity);
                 raceNextButton = true; 
         }
             
         if ((humanButton == true) & (femaleButton == true)) {
                 Instantiate (humanFemale, spawn.transform.position, Quaternion.identity);
                 raceNextButton = true; 
         }
             
         if ((centaurButton == true) & (maleButton == true)) {
                 Instantiate (centaurMale, spawn.transform.position, Quaternion.identity);
                 raceNextButton = true; 
         }
             
         if ((centaurButton == true) & (femaleButton == true)) {
                 Instantiate (centaurFemale, spawn.transform.position, Quaternion.identity);
                 raceNextButton = true; 
         }
             
         if ((demonButton == true) & (maleButton == true)) {
                 Instantiate (demonMale, spawn.transform.position, Quaternion.identity);
                 raceNextButton = true; 
         }

         if ((demonButton == true) & (femaleButton == true)) {
                 Instantiate (demonFemale, spawn.transform.position, Quaternion.identity);
                 raceNextButton = true; 
         }


     if (warriorButton == true) {
             rogueButton = false;
             beastMasterButton = false;
             iceMageButton = false;
             fireMageButton = false;
             ClassNext = true;
     }

     if (rogueButton == true) {
         warriorButton = false;
         beastMasterButton = false;
         iceMageButton = false;
         fireMageButton = false;
         ClassNext = true;
     }

     if (beastMasterButton == true) {
         rogueButton = false;
         warriorButton = false;
         iceMageButton = false;
         fireMageButton = false;
         ClassNext = true;
     }

     if (warriorButton == true) {
         rogueButton = false;
         beastMasterButton = false;
         iceMageButton = false;
         fireMageButton = false;
         ClassNext = true;
     }

     if (iceMageButton == true) {
         rogueButton = false;
         beastMasterButton = false;
         warriorButton = false;
         fireMageButton = false;
         ClassNext = true;
     }

     if (fireMageButton == true) {
         rogueButton = false;
         beastMasterButton = false;
         iceMageButton = false;
         warriorButton = false;
         ClassNext = true;
     }
 }

}

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

Answer by nj4242 · Sep 19, 2016 at 04:57 AM

Here:

 public void ShowWindow() {
      render = true;
  }
  public void HideWindow() {
      render = false;
  }
  public void OnGUI() {
      if (GUI.Button (new Rect (10,20,100,20), "Show Window"))
          ShowWindow();
      if (GUI.Button (new Rect (10,60,100,20), "Hide Window"))
          HideWindow();
      if (render) {
          windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
      }
  }
  public void DoMyWindow(int windowID) {
      if (GUI.Button (new Rect (10,20,100,20), "Hello World"))
          print ("Got a click");
  }
 

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

19 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

Related Questions

Enable/Disable Game Object With GUI Button 1 Answer

Enabling loop and disabling loop 1 Answer

[solved]how can i enable or disable a component of instantiated objects? 5 Answers

error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer 3 Answers

image not enabling 0 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