Change a script's boolean from a GUI Checkbox

Hello all,

I’m making a flight simulation game, and I need to make a checkbox that will allow users to toggle between training mode and normal mode. I have a boolean called “trainingMode” and it is by default set to false. In Unity, I click on the toggle gameobject, then go down to where it says “On Value Changed (Boolean.)” I click the plus, then drag my script into the “Object” box. I then click on where it says “No Function.” I don’t see my boolean in there. Can anyone help?

Toe Object you drag into the box has to be present in the scene; You can’t just drag the script from your Assets into it. If you did that, then note that you can’t directly access variables on a script this way; You can only call functions. So what you need to do is create a function that switches the boolean every time it is called, and then make the checkbox call that function.

public bool trainingMode = false;

void SwitchMode() {
     trainingMode = !trainingMode;
}