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 Max Designer · Jan 17, 2013 at 05:30 PM · javascriptguiresolution

How do i create an options menu?

How do i create an options menu, where when i change the volume from there it changes the level through out all my scenes and levels and i want to create an option to change the resolution as well and other things.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Great Alexander · Jan 17, 2013 at 05:43 PM

 Here is a code which all you need is to copy and paste it in c# file amd you will have a menu then attach this script to the Main Camera in the scene and you can pick if you want a background image to add to it:

 using UnityEngine;
 using System.Collections;
 
 public class Menu : MonoBehaviour 
 {
     public GUISkin guiSkin;
     public Texture2D background, LOGO;
     public bool DragWindow = false;
     public string levelToLoadWhenClickedPlay = "";
     public string[] AboutTextLines = new string[0];
 
 
     private string clicked = "", MessageDisplayOnAbout = "About \n ";
     private Rect WindowRect = new Rect((Screen.width / 2) - 100, Screen.height / 2, 200, 200);
     private float volume = 1.0f;
 
     private void Start()
     {
         for (int x = 0; x < AboutTextLines.Length;x++ )
         {
             MessageDisplayOnAbout += AboutTextLines[x] + " \n ";
         }
         MessageDisplayOnAbout += "Press Esc To Go Back";
     }
 
     private void OnGUI()
     {
         if (background != null)
             GUI.DrawTexture(new Rect(0,0,Screen.width , Screen.height),background);
         if (LOGO != null && clicked != "about")
             GUI.DrawTexture(new Rect((Screen.width / 2) - 100, 30, 200, 200), LOGO);
 
         GUI.skin = guiSkin;
         if (clicked == "")
         {
             WindowRect = GUI.Window(0, WindowRect, menuFunc, "Main Menu");
         }
         else if (clicked == "options")
         {
             WindowRect = GUI.Window(1, WindowRect, optionsFunc, "Options");
         }
         else if (clicked == "about")
         {
             GUI.Box(new Rect (0,0,Screen.width,Screen.height), MessageDisplayOnAbout);
         }else if (clicked == "resolution")
         {
             GUILayout.BeginVertical();
             for (int x = 0; x < Screen.resolutions.Length;x++ )
             {
                 if (GUILayout.Button(Screen.resolutions[x].width + "X" + Screen.resolutions[x].height))
                 {
                     Screen.SetResolution(Screen.resolutions[x].width,Screen.resolutions[x].height,true);
                 }
             }
             GUILayout.EndVertical();
             GUILayout.BeginHorizontal();
             if (GUILayout.Button("Back"))
             {
                 clicked = "options";
             }
             GUILayout.EndHorizontal();
         }
     }
 
     private void optionsFunc(int id)
     {
         if (GUILayout.Button("Resolution"))
         {
             clicked = "resolution";
         }
         GUILayout.Box("Volume");
         volume = GUILayout.HorizontalSlider(volume ,0.0f,1.0f);
         AudioListener.volume = volume;
         if (GUILayout.Button("Back"))
         {
             clicked = "";
         }
         if (DragWindow)
             GUI.DragWindow(new Rect (0,0,Screen.width,Screen.height));
     }
 
     private void menuFunc(int id)
     {
         //buttons 
         if (GUILayout.Button("Play Game"))
         {
             //play game is clicked
             Application.LoadLevel(levelToLoadWhenClickedPlay);
         }
         if (GUILayout.Button("Options"))
         {
             clicked = "options";
         }
         if (GUILayout.Button("About"))
         {
             clicked = "about";
         }
         if (GUILayout.Button("Quit Game"))
         {
             Application.Quit();
         }
         if (DragWindow)
             GUI.DragWindow(new Rect(0, 0, Screen.width, Screen.height));
     }
 
     private void Update()
     {
         if (clicked == "about" && Input.GetKey (KeyCode.Escape))
             clicked = "";
     }
 }
 
Comment
Add comment · Show 7 · 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 Great Alexander · Jan 17, 2013 at 05:45 PM 0
Share
 Here is a code which all you need is to copy and paste it in c# file amd you will have a menu then attach this script to the $$anonymous$$ain Camera in the scene and you can pick if you want a background image to add to it:
avatar image Max Designer · Jan 17, 2013 at 05:58 PM 0
Share

thanks alot.

avatar image NourWaLid · Jan 27, 2014 at 05:54 PM 0
Share

there is a problem with me == Assets/$$anonymous$$enu.cs(4,14): error CS0101: The namespace global::' already contains a definition for $$anonymous$$enu'

What should i do???

avatar image Jamora · Jan 27, 2014 at 05:55 PM 0
Share

That means you already have a class (or other definition) that is named $$anonymous$$enu in your project.

avatar image Infinite_Gamer · Feb 04, 2014 at 04:16 AM 0
Share

This really helped me a lot I got stuck at the same part.

Thanks

Show more comments
avatar image
0

Answer by TheMCProfesor · Jun 01, 2015 at 05:52 PM

What Do I do?


error.png (21.5 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 Noxury · Nov 15, 2015 at 02:59 PM 0
Share

Change the class name to the same the script is called!

avatar image
0

Answer by ahmad-hadia · Jun 26, 2017 at 09:38 PM

thanks , but i think it is bad for beginner , maybe you agree me or not , beginner do not need difficult code like this, if you have easy and simple ,it will be perfect , thanks you anyway ,good luck

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

20 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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

OnGUI Button 1 Answer

Is it possible to link character skill lists to a GUI, and if so, how? 3 Answers

Move the text in a GUI Button/Box 1 Answer

Gui Text Script 4 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