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 JeremyGames · Aug 01, 2016 at 09:06 AM · c#

How to add a GUI skin to this script!

Hello, Could someone make it so that this script has a variable GUI skin slot! using UnityEngine; using System.Collections;

 [System.Serializable]
 public class Map
 {
     public string name;
     public string levelName;
 }
  
 public class MainMenu : MonoBehaviour
 {
     public int curMenu = 0;
  
     private string[] settings;
     private int curIndex;
  
     public float dif = 1;
     HostData[] datas;
     public Vector2 scroll;
     private string gameName = "Server 666";
  
     //You have to change this!
     public string uniqueGameName = "MyUniqueGameName";
  
     //After which time will the server list be refreshed ?
     public float refreshTime = 10;
  
     public Map[] maps;
     public int curMapIndex;
  
     void Start()
     {
         InvokeRepeating("GetHostList", 0, refreshTime);
         settings = QualitySettings.names;
         Network.isMessageQueueRunning = false;
     }
  
     void GetHostList()
     {
         MasterServer.RequestHostList(uniqueGameName);
     }
  
     void Update()
     {
         dif = (Screen.width / 12.8f) / 100;
         datas = MasterServer.PollHostList();
     }
  
     void OnGUI()
     {
         if (curMenu == 0)
         {
             if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 - 80 * dif, 200 * dif, 50 * dif), "Play"))
             {
                 curMenu = 1;
             }
             if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 - 25 * dif, 200 * dif, 50 * dif), "Options"))
             {
                 curMenu = 2;
             }
             if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 + 30 * dif, 200 * dif, 50 * dif), "Quit"))
             {
                 Application.Quit();
             }
  
         }
         else if (curMenu == 1)
         {
             GUI.Box(new Rect(20 * dif, 20 * dif, 200 * dif, 200 * dif), "");
             GUILayout.BeginArea(new Rect(25 * dif, 25 * dif, 190 * dif, 190 * dif));
             gameName = GUILayout.TextField(gameName);
             if (GUILayout.Button("Start Server"))
             {
                 Network.InitializeSecurity();
                 Network.InitializeServer(17, 25001, /*!Network.HavePublicAddress()*/ true);
                 MasterServer.RegisterHost(uniqueGameName, gameName);
             }
             if (GUILayout.Button("Select Map"))
             {
                 curMenu = 5;
             }
             if (GUILayout.Button("Direct Connect"))
             {
                 Network.Connect("127.0.0.1", 25001);
             }
             if (GUILayout.Button("Back"))
             {
                 curMenu = 0;
             }
             GUILayout.EndArea();
             GUI.Box(new Rect(Screen.width - 400 * dif, 0, 400 * dif, Screen.height), "");
             GUILayout.BeginArea(new Rect(Screen.width - 400 * dif, 0, 400 * dif, Screen.height));
             GUILayout.Label("Avaiable Servers: " + datas.Length);
             scroll = GUILayout.BeginScrollView(scroll);
             foreach (HostData data in datas)
             {
                 GUILayout.BeginHorizontal();
                 GUILayout.Label(data.gameName + " Players: " + data.connectedPlayers + " / " + data.playerLimit);
                 if (GUILayout.Button("Connect"))
                 {
                     Network.Connect(data);
                 }
                 GUILayout.EndHorizontal();
             }
             GUILayout.EndScrollView();
             GUILayout.EndArea();
         }
         else if (curMenu == 2)
         {
             if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 - 80 * dif, 200 * dif, 50 * dif), "Audio"))
             {
                 curMenu = 3;
             }
             if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 - 25 * dif, 200 * dif, 50 * dif), "Graphics"))
             {
                 curMenu = 4;
             }
             if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 + 30 * dif, 200 * dif, 50 * dif), "Back"))
             {
                 curMenu = 0;
             }
         }
         else if (curMenu == 3)
         {
             AudioListener.volume = GUI.HorizontalSlider(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 - 25 * dif, 200 * dif, 50 * dif), AudioListener.volume, 0f, 1f);
             GUI.Label(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 - 45 * dif, 200 * dif, 50 * dif), "Volume: " + (AudioListener.volume * 100).ToString("F0") + " %");
             if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 + 30 * dif, 200 * dif, 50 * dif), "Back"))
             {
                 curMenu = 2;
             }
         }
         else if (curMenu == 4)
         {
             if (GUI.Button(new Rect(Screen.width / 2 - 75 * dif, Screen.height / 2 - 25 * dif, 150 * dif, 50 * dif), settings[curIndex]))
             {
                 QualitySettings.SetQualityLevel(curIndex);
             }
             if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 - 25 * dif, 20 * dif, 50 * dif), "←"))
             {
                 if (curIndex != 0) curIndex--;
                 else curIndex = settings.Length - 1;
             }
  
             if (GUI.Button(new Rect(Screen.width / 2 + 80 * dif, Screen.height / 2 - 25 * dif, 20 * dif, 50 * dif), "→"))
             {
                 if (curIndex != settings.Length - 1) curIndex++;
                 else curIndex = 0;
             }
  
             //I only made switching between quality settings. You can make it much more complex if you want.
             if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 + 30 * dif, 200 * dif, 50 * dif), "Back"))
             {
                 curMenu = 2;
             }
         }
         else if (curMenu == 5)
         {
             if (GUI.Button(new Rect(Screen.width / 2 - 75 * dif, Screen.height / 2 - 25 * dif, 150 * dif, 50 * dif), maps[curMapIndex].name))
             {
             }
             if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 - 25 * dif, 20 * dif, 50 * dif), "←"))
             {
                 if (curMapIndex != 0) curMapIndex--;
                 else curMapIndex = maps.Length - 1;
             }
  
             if (GUI.Button(new Rect(Screen.width / 2 + 80 * dif, Screen.height / 2 - 25 * dif, 20 * dif, 50 * dif), "→"))
             {
                 if (curMapIndex != maps.Length - 1) curMapIndex++;
                 else curMapIndex = 0;
             }
  
             if (GUI.Button(new Rect(Screen.width / 2 - 100 * dif, Screen.height / 2 + 30 * dif, 200 * dif, 50 * dif), "Back"))
             {
                 curMenu = 1;
             }
         }
     }
  
     void OnServerInitialized()
     {
         networkView.RPC("LoadLevel", RPCMode.AllBuffered, maps[curMapIndex].levelName);
         Debug.Log("Server initialized and ready");
     }
  
     [RPC]
     IEnumerator LoadLevel(string level)
     {
         Network.isMessageQueueRunning = false;
         yield return new WaitForSeconds(1);
         Application.LoadLevel(level);
         Network.isMessageQueueRunning = true;
     }
  
     void OnConnectedToServer()
     {
         Debug.Log("Connected to server");
         //Network.isMessageQueueRunning = true;
     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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

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

Improving script which Spawns enemies up to a required number 0 Answers

HOW TO ADD GRAVITY TO A OBJECT? 2 Answers

Unity WaitForSeconds Not Working Inside Update or a Loop 2 Answers

Zero Vector along Axis relative to another Vector 0 Answers

How can I write CPU usage on screen? 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