- Home /
Boolean Uncheck Inspector if False
In my script, I made a status check for my booleans:
var bomber : boolean = false;
var hybrid : boolean = true;
var fighter : boolean = false;
function StatusCheck() {
if(bomber){
hybrid = false;
fighter = false;
}
if(hybrid){
bomber = false;
fighter = false;
}
if(fighter){
hybrid = false;
bomber = false;
}
}
It works, so if two of the booleans are true, they cancel each other out. So it works. But the problem is, in the inspector, if you click on one boolean, it should automatically uncheck any of the other ones. For example, is bomber is true, but I click on the fighter in the inspector, bomber should become unchecked. It still says bomber is false, but the inspector doesn't uncheck it. How should I make it so it unchecks in inspector if I click on another boolean? (Putting it in the update function doesn't work).
Is this an editorscript or a script that you've got on a gameobject?
Answer by aldonaletto · Sep 24, 2011 at 09:09 PM
You can use this instruction at the script beginning:
@script ExecuteInEditMode()
This will make Update, FixedUpdate and OnGUI to execute in this script even while in Editor mode. You should rename your function to Update or just call it inside Update, and it will work - or kind of, because there's a problem: if bomber is set, trying to set hybrid or fighter will fail because bomber is executed first, and clears them both.
I can't think in a simple way to solve this problem - maybe using a GUI.SelectionGrid to select only one of three options, then set your 3 booleans according to the option selected.
Thank you, it works (Used the @script ExecuteInEdit$$anonymous$$ode() ).
Answer by msknapp · Sep 24, 2011 at 08:34 PM
scripts on a game object will only execute at runtime. If you want something to run before runtime, you must write an editor script.
Your answer
Follow this Question
Related Questions
Boolean values not behaving as expected. Please Help?! 0 Answers
The public bool will not change unless i set it 1 Answer
Why won't my if result to true? 1 Answer
Boolean problem!! 2 Answers