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 Keyojin · Feb 08, 2014 at 05:52 PM · c#arraysmenuelement

Menu, Game mode Array String to change settings?

I'm trying to get my game mode array to change setting. Like if game mode was selected to be hard cord mode. The level of difficulty can not be changed. If someone help me out with this? Here is my script.

 using UnityEngine;
 using System.Collections;
 [ExecuteInEditMode]
 public class NewGame : MonoBehaviour {
 //Background Picture
     public Texture OptionsBG;
 //Back Button Varabels
     public GameObject MMCamra;
     public GameObject OPCarmra;
     public GameObject OPCarmra2;
     public GameObject OPCarmra3;
 //Save file name
     public string PlayerName = "Game Name";
 //Level of Difficulty selector Drop menu
     public string[] Difficulty;
     public string selectedDifficulty = "Difficulty";
     private bool editing = false;
 //System Size Drop menu
     public string[] SystemSize;
     public string selctedSystemSize = "System Size";
     private bool editing2 = false;
 //resources Drop menu
     public string[] Resources;
     public string selctedResources = "Resource Availability";
     private bool editing3 = false;
 //Game Mode Drop Menu
     public string[] GameMode;
     public string selctedGameMode = "Game Mode";
     private bool editing4 = false;
 
 
 
     private void OnGUI(){
 
         GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), OptionsBG);
 
         GUI.Box (new Rect (Screen.width * .01f, Screen.height * .01f, Screen.width * .98f, Screen.height * .85f),"New Game");
 
         PlayerName = GUI.TextField(new Rect(Screen.width * .02f, Screen.height * .04f,Screen.width*.25f,25),PlayerName,27);
 
         GUI.Label(new Rect(Screen.width*0.02f,Screen.height*0.075f,Screen.width*.25f,25),"Game Mode");
         if (GUI.Button (new Rect (Screen.width * .02f, Screen.height * .1f, Screen.width * .25f, 25), selctedGameMode)) {
             editing = false;editing2 =false;editing3 =false;editing4 =true;
         } 
         if (editing4)
         {
             for (int x = 0; x < GameMode.Length; x++)
             {
                 if (GUI.Button(new Rect(Screen.width*.27f,(Screen.height*.1f)+(25*x) ,Screen.width*.25f,25 ), GameMode[x]))
                 {
                     selctedGameMode = GameMode[x];
                     editing4 = false;
                 }
             }
         }
 
         GUI.Label(new Rect(Screen.width*0.02f,Screen.height*0.145f,Screen.width*.25f,25),"Level of Difficulty");
         if (GUI.Button (new Rect (Screen.width * .02f, Screen.height * .17f, Screen.width * .25f, 25), selectedDifficulty)) {
             editing = true;editing2 =false;editing3 =false;editing4 =false;
                 } 
         if (editing)
         {
             for (int x = 0; x < Difficulty.Length; x++)
             {
                 if (GUI.Button(new Rect(Screen.width*.27f,(Screen.height*.17f)+(25*x) ,Screen.width*.25f,25 ), Difficulty[x]))
                 {
                     selectedDifficulty = Difficulty[x];
                     editing = false;
                 }
             }
 
         }
         GUI.Label(new Rect(Screen.width*0.02f,Screen.height*0.215f,Screen.width*.25f,25),"System Size");
         if (GUI.Button (new Rect (Screen.width * .02f, Screen.height * .24f, Screen.width * .25f, 25), selctedSystemSize)) {
             editing = false;editing2 =true;editing3 =false;editing4 =false;
         } 
         if (editing2)
         {
             for (int x = 0; x < SystemSize.Length; x++)
             {
                 if (GUI.Button(new Rect(Screen.width*.27f,(Screen.height*.24f)+(25*x) ,Screen.width*.25f,25 ), SystemSize[x]))
                 {
                     selctedSystemSize = SystemSize[x];
                     editing2 = false;
                 }
             }
             
         }
         GUI.Label(new Rect(Screen.width*0.02f,Screen.height*0.285f,Screen.width*.25f,25),"Amount of Resources");
         if (GUI.Button (new Rect (Screen.width * .02f, Screen.height * .31f, Screen.width * .25f, 25), selctedResources)) {
             editing = false;editing2 =false;editing3 =true;editing4 =false;
         } 
         if (editing3)
         {
             for (int x = 0; x < Resources.Length; x++)
             {
                 if (GUI.Button(new Rect(Screen.width*.27f,(Screen.height*.31f)+(25*x) ,Screen.width*.25f,25 ), Resources[x]))
                 {
                     selctedResources = Resources[x];
                     editing3 = false;
                 }
             }
             
         }
 
 
 
         if (GUI.Button (new Rect (Screen.width * .15f, Screen.height * .9f, Screen.width * .1f, 25),"Reset")) {
             PlayerName = "Game Name";
             selectedDifficulty = "Difficulty Level";editing=false;
             selctedSystemSize = "System Size";editing2=false;
             selctedResources = "Resource Availability";editing3=false;
             selctedGameMode = "Game Mode";editing4=false;
         } 
 
         
         if (GUI.Button (new Rect (Screen.width * .01f, Screen.height * .9f, Screen.width * .1f, 25), "Back")) {
             Debug.Log("Switching to Main Menu");
             MMCamra.gameObject.SetActive(true);
             OPCarmra.gameObject.SetActive(false);
             OPCarmra2.gameObject.SetActive(false);
             OPCarmra3.gameObject.SetActive(false);
         }    
     }
 }
 
Comment
Add comment · Show 2
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 RudyTheDev · Feb 09, 2014 at 11:10 AM 0
Share

I'm not sure what's wrong with this, but I pasted the code and it works for me fine. Are you sure you have filled in the values in the inspector?

avatar image Keyojin · Feb 09, 2014 at 07:49 PM 0
Share

I want to make to make it so when i select the game mode element to hard core. You cant make level of difficulty to easy.

 Game $$anonymous$$ode = Hard Core                             Game $$anonymous$$ode = Normal
 Difficult = Vary Hard //Can NOT be changed        Difficult = //What ever you want it be
 System Size = Normal //Can NOT be changed         System Size = //What ever you want
 Resource = Few //Can NOT be Changed               Resource = //What ever you want
 

1 Reply

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

Answer by RudyTheDev · Feb 09, 2014 at 08:12 PM

Here is the simple version (without any big code refactoring):

 using UnityEngine;
 using System.Collections;
 
 [ExecuteInEditMode]
 public class NewGame : MonoBehaviour
 {
     //Background Picture
     public Texture OptionsBG;
     //Back Button Varabels
     public GameObject MMCamra;
     public GameObject OPCarmra;
     public GameObject OPCarmra2;
     public GameObject OPCarmra3;
     //Save file name
     public string PlayerName = "Game Name";
     //Level of Difficulty selector Drop menu
     public string[] Difficulty;
     public string selectedDifficulty = "Difficulty";
     private bool editing = false;
     //System Size Drop menu
     public string[] SystemSize;
     public string selctedSystemSize = "System Size";
     private bool editing2 = false;
     //resources Drop menu
     public string[] Resources;
     public string selctedResources = "Resource Availability";
     private bool editing3 = false;
     //Game Mode Drop Menu
     public string[] GameMode;
     public string selctedGameMode = "Game Mode";
     private bool editing4 = false;
 
 
 
     private void OnGUI()
     {
 
         GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), OptionsBG);
 
         GUI.Box(new Rect(Screen.width * .01f, Screen.height * .01f, Screen.width * .98f, Screen.height * .85f), "New Game");
 
         PlayerName = GUI.TextField(new Rect(Screen.width * .02f, Screen.height * .04f, Screen.width * .25f, 25), PlayerName, 27);
 
         GUI.Label(new Rect(Screen.width * 0.02f, Screen.height * 0.075f, Screen.width * .25f, 25), "Game Mode");
         if (GUI.Button(new Rect(Screen.width * .02f, Screen.height * .1f, Screen.width * .25f, 25), selctedGameMode))
         {
             editing = false; editing2 = false; editing3 = false; editing4 = true;
         }
         if (editing4)
         {
             for (int x = 0; x < GameMode.Length; x++)
             {
                 if (GUI.Button(new Rect(Screen.width * .27f, (Screen.height * .1f) + (25 * x), Screen.width * .25f, 25), GameMode[x]))
                 {
                     selctedGameMode = GameMode[x];
                     if (selctedGameMode == "Hardcore") // Or replace with the actual GameMode[N] value
                     {
                         selectedDifficulty = "Vary Hard"; // Or replace with the actual Difficulty[N] etc. values
                         selctedSystemSize = "Normal";
                         selctedResources = "Few";
                     }
                     editing4 = false;
                 }
             }
         }
 
         GUI.Label(new Rect(Screen.width * 0.02f, Screen.height * 0.145f, Screen.width * .25f, 25), "Level of Difficulty");
         if (GUI.Button(new Rect(Screen.width * .02f, Screen.height * .17f, Screen.width * .25f, 25), selectedDifficulty))
         {
             if (selctedGameMode != "Hardcore") // Or replace with the actual GameMode[N] value (and the ones below)
             {
                 editing = true; editing2 = false; editing3 = false; editing4 = false;
             }
         }
         if (editing)
         {
             for (int x = 0; x < Difficulty.Length; x++)
             {
                 if (GUI.Button(new Rect(Screen.width * .27f, (Screen.height * .17f) + (25 * x), Screen.width * .25f, 25), Difficulty[x]))
                 {
                     selectedDifficulty = Difficulty[x];
                     editing = false;
                 }
             }
 
         }
         GUI.Label(new Rect(Screen.width * 0.02f, Screen.height * 0.215f, Screen.width * .25f, 25), "System Size");
         if (GUI.Button(new Rect(Screen.width * .02f, Screen.height * .24f, Screen.width * .25f, 25), selctedSystemSize))
         {
             if (selctedGameMode != "Hardcore")
             {
                 editing = false; editing2 = true; editing3 = false; editing4 = false;
             }
         }
         if (editing2)
         {
             for (int x = 0; x < SystemSize.Length; x++)
             {
                 if (GUI.Button(new Rect(Screen.width * .27f, (Screen.height * .24f) + (25 * x), Screen.width * .25f, 25), SystemSize[x]))
                 {
                     selctedSystemSize = SystemSize[x];
                     editing2 = false;
                 }
             }
 
         }
         GUI.Label(new Rect(Screen.width * 0.02f, Screen.height * 0.285f, Screen.width * .25f, 25), "Amount of Resources");
         if (GUI.Button(new Rect(Screen.width * .02f, Screen.height * .31f, Screen.width * .25f, 25), selctedResources))
         {
             if (selctedGameMode != "Hardcore")
             {
                 editing = false; editing2 = false; editing3 = true; editing4 = false;
             }
         }
         if (editing3)
         {
             for (int x = 0; x < Resources.Length; x++)
             {
                 if (GUI.Button(new Rect(Screen.width * .27f, (Screen.height * .31f) + (25 * x), Screen.width * .25f, 25), Resources[x]))
                 {
                     selctedResources = Resources[x];
                     editing3 = false;
                 }
             }
 
         }
 
 
 
         if (GUI.Button(new Rect(Screen.width * .15f, Screen.height * .9f, Screen.width * .1f, 25), "Reset"))
         {
             PlayerName = "Game Name";
             selectedDifficulty = "Difficulty Level"; editing = false;
             selctedSystemSize = "System Size"; editing2 = false;
             selctedResources = "Resource Availability"; editing3 = false;
             selctedGameMode = "Game Mode"; editing4 = false;
         }
 
 
         if (GUI.Button(new Rect(Screen.width * .01f, Screen.height * .9f, Screen.width * .1f, 25), "Back"))
         {
             Debug.Log("Switching to Main Menu");
             MMCamra.gameObject.SetActive(true);
             OPCarmra.gameObject.SetActive(false);
             OPCarmra2.gameObject.SetActive(false);
             OPCarmra3.gameObject.SetActive(false);
         }
     }
 }
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 Keyojin · Feb 09, 2014 at 09:40 PM 0
Share

Cool, thanks a lot. I can't believe it was that simple.

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

19 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

Related Questions

Distribute terrain in zones 3 Answers

Basic object creation in arrays! Syntax error! 1 Answer

Multiple Cars not working 1 Answer

Failed setting triangles in my mesh 1 Answer

Need help with converting an array to a list in C#` 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