I’m trying to use toggle as a checkbox that only gets called once. The checkbox should display on start, and continue to display after it is clicked. On click I want it to change state, and then perform an action only once. That action should differ, depending on whether that state is checked or unchecked.
Here is my code.
public bool checkBoxClicked = true;
public bool checkBox = false;
void OnGUI()
{
public bool checkBoxClicked = true;
public bool checkBox = false;
if (checkBoxClicked == true)
{
checkBox = GUI.Toggle(new Rect(25, 25, 100, 30), checkBox, "checkBox");
checkBoxClicked = false;
Debug.Log("Inside if");
}
This code does not display the toggle, but it does output “Inside if” to the console.