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 Legrandes · Mar 20, 2015 at 03:38 PM · guiscript errorproblem during runtime

C# script works wrong ( GUI ) How to fix it ?

Hello everybody. I am working on puzzle game. On the first scene i have got menu : Play More Games Exit. alt text

When i press "Play".This menu is closing and Difficulty menu should be open. It works. alt text

When i press "MORE Games" it works only from second time. First time it opens Difficulty menu. But if i press second time "More Games" it works good and open "More Games menu.WHy??

When i press Exit it always opens More Games Menu. Why? I wrote this line of code in script Application.Quit ();

Then i have 1 more mistake.

Difficulty menu contains : Normal - when i press normal , normal games are opening Superior - when i press superior , AGAIN NORMAL GAMES ARE OPENING . WHY ?? Genius - works good. Back - works good.

I think it is a GUI problem maybe i could be wrong. Help me please to fix this problem please.

1.png (268.9 kB)
2.png (274.2 kB)
Comment
Add comment · Show 1
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 Xymbiot3 · Mar 20, 2015 at 03:45 PM 0
Share

Can you post the scripts you're using that you're invoking on these buttons? If some are working and some aren't it sounds like a script or a configuration issue.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Legrandes · Mar 20, 2015 at 04:10 PM

i am a beginner in scripting. i wish everybody can understand what i wrote. if not i will explain everything.

i have gameobjects in hierachy not active. when i press on the button the right menu is opening. alt text

 public GameObject DifficultyMenu;
     public GameObject moregamesmenu;
     public GameObject normallevelmenu;
     public GameObject superiorlevelmenu;
     public GameObject glmenu;
 
     
 
     public bool Play;
     public bool difficulty;
     public bool normal;
     public bool moregames;
     public bool exit;
     public bool back;
     public bool backn;
     public bool backg;
     public bool backs;
     public bool home;
 
     public float width;
     public float height;
     public float hm;
 
     void Update () {
         OnGUI ();
 
     }
     void OnGUI()
     {
         if (GUI.Button (new Rect (Screen.width / width, Screen.height / height * hm, Screen.width/4, Screen.height/2), textura, stil) )
         {
             knopka();
         }
 
     }
     void knopka()
     {  
 
                         if (Play)
         Application.LoadLevel (1);
                               
                         if (difficulty) {
         
                                 DifficultyMenu.SetActive (true);
                                 MainMenu.SetActive (false);
                         }
                         if (normal) 
                         {
                         chekstatusnormal();        
                         }
                         if (superior) 
                         {
                         chekstatussuperior();        
                         }
                         
                         if (moregames) 
                         {
                         moregamesmenu.SetActive (true);
                         MainMenu.SetActive (false);
                         }
         
                         if (back) {
                                 checkstatus ();
                         }
                         if (backn) 
                          {
                         chekstatusabckn();
                         }
                         if (backs) 
                         {
                         chekstatusabcks();
                         } if (backg) 
                         {
                         chekstatusabckg();
                         }
 
                         if (exit) 
                         {
                         Application.Quit ();
                          }
                         if (home)
                         {
                         Application.LoadLevel ("menu");
                         }
 
 
     }   
     void checkstatus()
     {
       if (!MainMenu.activeInHierarchy && DifficultyMenu.activeInHierarchy)
                         MainMenu.SetActive (true);
                          DifficultyMenu.SetActive (false);
     }
     void chekstatusnormal()
     {
         if (!normallevelmenu.activeInHierarchy && DifficultyMenu.activeInHierarchy  )
             normallevelmenu.SetActive (true);
         DifficultyMenu.SetActive (false);
     }
         void chekstatussuperior()
     {
         if (!superiorlevelmenu.activeInHierarchy && DifficultyMenu.activeInHierarchy  )
             superiorlevelmenu.SetActive (true);
         DifficultyMenu.SetActive (false);
     }
     void chekstatusabckn()
     {
         if (!DifficultyMenu.activeInHierarchy && normallevelmenu.activeInHierarchy)
             normallevelmenu.SetActive (false);
         DifficultyMenu.SetActive (true);
     }
     void chekstatusabcks()
     {
         if (!DifficultyMenu.activeInHierarchy && superiorlevelmenu.activeInHierarchy)
             superiorlevelmenu.SetActive (false);
         DifficultyMenu.SetActive (true);
     }
     void chekstatusabckg()
     {
         if (!DifficultyMenu.activeInHierarchy && glmenu.activeInHierarchy)
             glmenu.SetActive (false);
         DifficultyMenu.SetActive (true);
     }



3.png (24.2 kB)
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 Xymbiot3 · Mar 20, 2015 at 04:26 PM 0
Share

It seems like it would be a problem related to when you set the variables you 'if check'. So when do you set 'moregames' or 'superior' to true?

Also just a note, you shouldn't need to call OnGUI() from Update() if you're using the base Unity functions.

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

Draw call minimizer 1 Answer

[Solved] Built in GUI continuously Loads through different Options. 1 Answer

c# - void method from external class. 2 Answers

drawing a box with GUI 3 Answers

Why is my code duplicating the name of a button? styling gui 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