- Home /
Question by
Chocolade · May 23, 2017 at 09:59 PM ·
c#scripting problemscript.
How can i switch the text of a GUILayout.Toggle depending if false or true ?
void OnGUI()
{
GUI.Window(0, rect, Menu, "Instantiate Objects Menu");
}
void Menu(int i)
{
if (GUILayout.Button("Generate new objects"))
{
}
if (GUILayout.Toggle(false, "Destroy old objects"))
{
}
}
What i want to do is that if the GUILayout.Toggle is true show the text "Destroy old objects" and if it's true show "Keep old objects".
Comment
public bool toogleValue;
void OnGUI()
{
GUI.Window(0, rect, $$anonymous$$enu, "Instantiate Objects $$anonymous$$enu");
}
void $$anonymous$$enu(int i)
{
if (GUILayout.Button("Generate new objects"))
{
}
string toggleLabel = "";
if (toogleValue)
{
toggleLabel = "$$anonymous$$eep Objects";
}
else
{
toggleLabel = "Destroy old objects";
}
if (GUILayout.Toggle(toogleValue, toggleLabel))
{
}
}
Best Answer
Answer by Bill9009 · May 24, 2017 at 03:14 AM
This is the ternary operator it works like :
bool expression ? if true : if false;
(GUILayout.Toggle ? "Keep old objects" : "Destroy old objects");