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 cystemic · May 29, 2014 at 06:33 AM · guibooleanonguibooleans

Hiding OnGUI?

Hi everybody,

Having a bit of an issue with OnGUI(). I have a boolean called Selecting which I would like to use to control when OnGUI() displays a scrollview onto my screen. So far it works ok. When I switch Selecting to true, it pops up with the arrays of buttons I want but when I click the button and change Selecting back to false, the scrollview remains, even though the functions that the button press calls successfully do their job. Is there a way to stop OnGUI() from doing this? Any help would be appreciated.

     void OnGUI(){
         if (Selecting) {
             scrollPosition = GUI.BeginScrollView (new Rect(0,0,Screen.width+20,Screen.height),scrollPosition,new Rect(0,0,Screen.width,(Screen.height/6)*30-10),false,false);
                         for (int i=0; i<20; i++) {
                                 if(Selecting){
                                         rect = new Rect(0,i*(Screen.height/4),Screen.width,Screen.height/4);
                                         Tub = Resources.Load("Art/Tubs/"+Flavour[i], typeof(Texture)) as Texture;
                                         Icon =Resources.Load("Art/Icons/"+Flavour[i], typeof(Texture)) as Texture;
                                         GUI.DrawTexture(rect,Tub);
                                         GUI.Label (rect,Icon);
                                         if(GUI.Button (rect,Flavour[i],Tubs)){
                                             
                                             SelectedFlavour = Flavour[i];
                                             print(SelectedFlavour);
                                             FlavourSwitch();
                                             Selecting = false;
                                             break;    
                                         }
                                 }
                             } 
                         GUI.EndScrollView ();
                     }
 
     }
Comment
Add comment · Show 4
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 fafase · May 29, 2014 at 07:16 AM 1
Share

Why do you have twice the Selecting check? I don't see why it would be the reason for your problem but I don't see why you have either.

avatar image benjaminwharton · May 29, 2014 at 07:36 AM 0
Share

All I can think of is that 'Selecting' isn't being changed. Try outputting its state to the log and see what happens.

avatar image Magok_Stelios · May 29, 2014 at 12:01 PM 0
Share

as said above, try to remove the if(selecting) from the for loop and the break at the end then you have to do some debugging with your selecting flag... check when it change and if it actualy does...

avatar image cystemic · May 29, 2014 at 09:42 PM 0
Share

Selecting is changing but the GUI still displays when I want it gone. For some reason if there isn't a second selecting check, it just loads up the GUI as soon as I enter the game :/

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by cystemic · May 30, 2014 at 02:48 AM

I've tried to regulate this by moving the GUI to an outside object which is created when the GUI is needed and destroyed when something in the gui is selected but I still get the same result. The GUI is still suspended on the screen after i press the button and the object is not destroyed. I have tried every kind of combination of Destroy but it just stays in the hierarchy. Please help :(

 public class Test : MonoBehaviour {
 
     ScoopAssembler assembler;
     // Use this for initialization
     void Start () {
         assembler = GameObject.Find ("Generator 1").GetComponent<ScoopAssembler> ();
     }
 
     void OnGUI(){
     //if (assembler.Selecting==true) {
             assembler.scrollPosition = GUI.BeginScrollView (new Rect(0,0,Screen.width+20,Screen.height),assembler.scrollPosition,new Rect(0,0,Screen.width,(Screen.height/6)*30-10),false,false);
         for (int i=0; i<20; i++) {
             //if(Selecting){
                 assembler.rect = new Rect(0,i*(Screen.height/4),Screen.width,Screen.height/4);
                 assembler.Tub = Resources.Load("Art/Tubs/"+assembler.Flavour[i], typeof(Texture)) as Texture;
                 assembler.Icon =Resources.Load("Art/Icons/"+assembler.Flavour[i], typeof(Texture)) as Texture;
                 GUI.DrawTexture(assembler.rect,assembler.Tub);
                 GUI.Label (assembler.rect,assembler.Icon);
                 if(GUI.Button (assembler.rect,assembler.Flavour[i],assembler.Tubs)){
                 
                     assembler.SelectedFlavour = assembler.Flavour[i];
                     print(assembler.SelectedFlavour);
                     assembler.FlavourSwitch();
                     assembler.Selecting = false;
                     print ("in for loop: "+assembler.Selecting);
                     Destroy(this.gameObject);
                 //}
             }
         } 
         GUI.EndScrollView ();
     //}
 
     
 }
 }
 
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

22 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

Related Questions

Multiple Cars not working 1 Answer

[Solved] GUI Error? 1 Answer

How to be specific and universal with your onGUI controls? 1 Answer

GUI Box appear when you are close to something? 1 Answer

Unity says there is no such thing as a boolean. 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