- Home /
The question is answered, right answer was accepted
Set Bool in Inspector to true or False
OK this should be simple but I always have rouble trying to do this. I have a script with options in the inspector that can be checked to on or of. I am trying to make a UI button call that will toggle the option in the inspector on or off, right now I can turn it on with my gobble button but always have difficulty trying to figure out how to turn it back off with the same toggle button.
public void Loop() {
loop = true;
}
Answer by orcinusdev · Mar 14, 2015 at 05:51 PM
if Loop() is the method that the button is calling, just check:
public void Loop() {
if(loop) // you can also write if(loop == true)
loop = false;
else
loop = true;
}
Ah thankyou orcinusdev, That was it, I can never seem to get that to sink into my fat head ;) lol
Answer by Mmmpies · Mar 14, 2015 at 05:48 PM
Just use
loop = !loop;
So you set it to the opposite of what it currently is.
Follow this Question
Related Questions
Array SetActive C# Unity 1 Answer
Problems with save 1 Answer
Unity Multiple Toggle Buttons Reversing 2 Answers
What's wrong code if-else with tag script ? 0 Answers
SetActive - setactive(true) for one object, setactive(false) to the rest 1 Answer