Need help understanding toggle code.
So I was trying to create a Toggle for my GUI using IMGUI, but once the toggle was pressed down I didn't want it to be able to be pressed back up so to speak, essentially trying to create a one time use toggle. After messing around with the code for a while, I came up with this,
void OnGUI()
{
if (!ToggleArray[0])
ToggleArray[0] = GUI.Toggle(new Rect(TogglePoints[0], ToggleSize), ToggleArray[0], "Toggle1", testGUIskin.customStyles[0]);
else
{
ToggleArray[0] = GUI.Toggle(new Rect(TogglePoints[0], ToggleSize), true, "Toggle1", testGUIskin.customStyles[0]);
ToggleArray[0] = true;
}
which works, but I'm a little confused as to why. Shouldnt the first line in the else statement always set the ToggleArray[0] to true anyways? However, if I remove the ToggleArray[0] = true; line, then the code no longer works.
A secondary question is when does the OnGUI method handle GUI input? Does it always finish running the method before handling input such as Toggle presses, or can it happen during its execution?
Thanks in advance.
Your answer
Follow this Question
Related Questions
Toggle Button: hope it toggle once but it toggle many times 1 Answer
Latching Toggle Button Help 2 Answers
Toggling checkbox in toggle in GUILayout.Toggle 1 Answer
Toggle UI Text With UI Toggle Button 1 Answer
Location Does Not Change 1 Answer