How to basically use GUI.Toggle?

This has been killing me for days. You see, i’m trying to make an aceptable Pause Menu in wich i have already made a button that takes the user to an Options Screen, and in that options screen i want to have a variety of toggles that can be showed enabled and disabled (change the state they are showing), but the problem i don’t know the basics of the GUI.Toggle as well as the GUILayout.Toggle (this is what i’m trying to use, i’ve already took a look at Scripting Reference…but the explanation is poor, only explains how to put text or an image, but nothing else).

I want, in this first case, to set a gameobject to enabled or disabled depending in a respective toggle (let’s call it ‘NevDensa’). The gameobject contains a Particle system which i tweaked to simulate a snow storm, but because it is maybe a bit performance expensive, i want rhe users to be able to enable or disable it as they need)

I’m not sure how to do that, because i don’t know how to switch between the two states, and worst of all…, whatever i’m running the game and try to click the toggle…the toggle remains always as active in the screen (i got it to successfully disable the gameobject i mentioned…but, it remains as activated in the screen, and i can’t click to enable the gameobject again…because the gameobject can’t be reenabled)

What i want to do would be…

Dense Snow Storm: (Here would be the toggle, activated by default, and when clicked, set the gameobject to false and…possibly change the visual text from ‘Enabled’ to ‘Disabled’ on screen?)

I hope i explained my situation clearly, but only to be sure…

[12037-question+about+toggles.jpg|12037]

Thanks in advance!

I believe this snippet would work, though I haven’t tested it. GO is the gameobject you want to set active/disabled by the toggle and toggleBool is a boolean class variable.

		if(toggleBool)
			toggleBool = GUI.Toggle (new Rect (25, 25, 100, 30), toggleBool, "Active");
		else
			toggleBool = GUI.Toggle (new Rect (25, 25, 100, 30), toggleBool, "Disabled");
		
		if(GUI.changed)
			GO.SetActive(toggleBool);

The following code will allow you to choose one of red, green, or blue. The selected value will be returned in the variable colGridInt as a value between 0 and 2.

//js
var colGridInt : int = 0;
var colStrings : String[] = ["red", "green", "blue"];
          
function OnGUI() {
	GUILayout.BeginVertical("Box");
	colGridInt = GUILayout.SelectionGrid (colGridInt, colStrings, 1, "toggle");
	
	if (GUILayout.Button("Start")){
		Debug.Log(colStrings[colGridInt]);
	}
	GUILayout.EndVertical();
}