- Home /
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);
}
}
}
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?
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
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);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613132920im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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