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 ham · Aug 24, 2014 at 08:10 PM · guibuttonboolean

boolean is true and false at a same time

with no Additional Details , this is my code

void OnGUI() {

         if (ShopGui) firstInv();
         if (secondGUI) secondInv();
       
       
     }
     void firstInv()
     {
         print(ShopGui);
         if(ShopGui)
         {
             GUI.BeginGroup(new Rect(0, 0, Screen.width, Screen.height), "");
             int i = 0;
             for (int X = 0; X < 3; X++)
             {
                 for (int Y = 0; Y < 3; Y++)
                 {
                     Rect slotRect = new Rect(X * ((Screen.width / 4) + 10), Y * ((Screen.width / 4) + 10), Screen.width / 4, Screen.width / 4);
                     if(GUI.Button(slotRect, ""))
                     {
                         Debug.Log("Clicked the button with an image");
                         ShopGui = false;
                         secondGUI = true;
                     }
                     
                     menuSecond[i] = menuFirst[i];
                     GUI.DrawTexture(slotRect, menuSecond[i].view);
                     i++;
 
                 }
 
             }
             GUI.EndGroup();
         }
        
     }
     void secondInv()
     {
         if(secondGUI)
         {
             if( GUI.Button(new Rect(50, 50, 100, 100), "SecondInv"))
             {
  ShopGui = true;
  secondGUI = false;
             }
            
         }
        
     }

 

but something strange happens , the 1st time i click on a gui .button both of my gui menus appear on screen and the shopgui boolan is both true and false.....but the next times this problems goes away... would anybody tell me why this happens

Comment
Add comment · Show 3
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 Addyarb · Aug 24, 2014 at 08:48 PM 0
Share

Right off the bat I'd say it's because you are not calling GUI functions within OnGUI, but I may be wrong.

avatar image NoseKills · Aug 24, 2014 at 08:54 PM 0
Share

Both of your method calls are inside the OnGUI so no problem there.

Do the menus stay open at the same time for long or do they just flash together momentarily?

What are the staring values to ShopGui and secondGui ?

avatar image ham · Aug 25, 2014 at 06:19 AM 0
Share

yes my both functions are in OnGUI and i dont think this be the reason , the first time i do single click they both appear screen ,ofcource a little pale and in my console shopGui variable is true and false and the secondgui is true , but when i double click on them i havent got this problem ,but in the next times when single click shopgui get false and secondgui true...

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ham · Aug 26, 2014 at 07:00 AM

ok i think it was for changing monodevolop to VS in middle of way , i started with VS the same code and it works perfectly thanks from your comments

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 Kiwasi · Aug 27, 2014 at 08:08 PM

What evidence did you have that the bool is both true and false? A bool cannot be both true and false. It can change between true and false.

The most likely problem was both bools were initialised as true. This would explain why the problem only occurred on the fist instance. I'm picking you fixed this without realising it when you rewrote the script.

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 ham · Sep 07, 2014 at 07:27 AM 0
Share

console was my evidence , ofcourse you are completely right but maybe because of high frame rate i saw the true and false messages together

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

25 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

Related Questions

UI button doesn't appear - c# 3 Answers

Boolean function doesn't work anymore 2 Answers

Problems with simple dialogue 0 Answers

OnGUI button created by a foreach loop 4 Answers

[C#] Xbox D'Pad to cycle through GUI.Buttons? 2 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