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 /
  • Help Room /
avatar image
0
Question by Cysar · Mar 17, 2017 at 08:36 PM · panelmain menu

I m a beginner and I need help with a panel

Could someone describe me how to make a setting panel or an window for my main menu spawned by a button click and disabled by clicking on the sides of the panrl. pls step by step and in an easy english

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
0

Answer by nathanthesnooper · Mar 18, 2017 at 04:07 AM

     public GameObject panel;
     public GameObject[] panelParameters;
 
     public void TogglePanel () {
 
         //
         // This will make the panel hidden if it was previously on, and vice versa.
         //
         // The function will be called from an X button in the panel, and on a button to show the panel, Ex: a "Settings" Button.
         //
 
         if (!panel.activeInHierarchy) {
             LoadPanel ();
         }
 
         panel.SetActive (!panel.activeInHierarchy);
 
     }
 
     public void LoadPanel () {
         
         //
         // This function should be called in the start function, or it can be called when the settings menu is opened,
         // meaning on the TogglePanel() function where panel.activeInHierarchy is false;
         //
 
         for (int i = 0; i < panelParameters.Length; i++) {
 
             GameObject parameter = panelParameters [i];
 
             if (parameter.GetComponent<InputField> () != null) {
                 parameter.GetComponent<InputField> ().text = PlayerPrefs.GetString ("panelParameter_" + i);
             }
 
             if (parameter.GetComponent<Toggle> () != null) {
                 parameter.GetComponent<Toggle> ().isOn = intToBool(PlayerPrefs.GetInt ("panelParameter_" + i));
             }
 
             if (parameter.GetComponent<Dropdown> () != null) {
                 parameter.GetComponent<Dropdown> ().value = PlayerPrefs.GetInt ("panelParameter_" + i);
             }
 
         }
 
     }
 
     public void SavePanel () {
 
         //
         // This function should be called each frame, or for better performance every time you change a value in
         // the settings. Can be done using the OnValueChanged() on most Buttons, InputFields, Toggles, and Dropdowns.
         //
 
         for (int i = 0; i < panelParameters.Length; i++) {
 
             GameObject parameter = panelParameters [i];
 
             if (parameter.GetComponent<InputField> () != null) {
                 PlayerPrefs.SetString ("panelParameter_" + i, parameter.GetComponent<InputField> ().text);
             }
 
             if (parameter.GetComponent<Toggle> () != null) {
                 PlayerPrefs.SetInt ("panelParameter_" + i, boolToInt(parameter.GetComponent<Toggle> ().isOn));
             }
 
             if (parameter.GetComponent<Dropdown> () != null) {
                 PlayerPrefs.SetInt ("panelParameter_" + i, parameter.GetComponent<Dropdown> ().value);
             }
 
         }
 
     }
 
     public int boolToInt (bool input) {
 
         //
         // Returns an integer (1/0) based on a bool (true/false) input; Due to the fact that there is no
         // PlayerPrefs.Set/GetBool();
         //
 
         if (input) {
             return 1;
         } else {
             return 0;
         }
     }
 
     public bool intToBool (int input) {
 
         //
         // Returns a bool (true/false) based on an integer (1/0) input; Due to the fact that there is no
         // PlayerPrefs.Set/GetBool();
         //
 
         if (input == 1) {
             return true;
         } else {
             return false;
         }
     }

Final thoughts:

-This took me WAY too long to do :)

-Please fix basic compiler errors if there is some... :)

-Use a LayoutGroup on the panel, so that all of the parameters are lined up nicely

-You can set panelParameters from panel's children, but it is more resource intensive and takes more time in the long run.

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

96 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 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 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 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

Accessing my 'Options' panel from another script. 1 Answer

Attach UI elements to screen corners 1 Answer

setactive panel from other scene 0 Answers

How to re-size 2D SpriteRenderer to the size of Canvas panel? 0 Answers

Back to main menu after 3s from show ui text 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