I want to make that in the Inspector if the game is running or not running when i check one of the checkboxes the two others will be unchecked. I mean that in any case only one checkbox can be checked each time.
I just mindlessly copied function from above. Sorry about that.
Just put this code inside Update function instead of Start and remove while(true).
Edit:
Working script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class CheckBoxes : MonoBehaviour {
public bool stateForward = false, stateReverse = false, stateRandom = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (stateForward == true)
{
stateRandom = false;
stateReverse = false;
}
else if (stateReverse == true)
{
stateRandom = false;
stateForward = false;
}
else if (stateRandom == true)
{
stateForward = false;
stateReverse = false;
}
}
}
I think the issue you’ll find with that code is that you won’t be able to go from certain checks to certain other checks. For example, if stateForward is checked, then you click on stateRandom, it will disable stateRandom in the first block of that if statement, and leave you with just stateForward.
I think trying to do this without editor scripting is a fool’s errand. It’s doable, but you’re gonna need like twice the amount of code (basically, you need to track which one was checked before in a private variable, and then make an OnValidate, and check EVERY COMBINATION of checkboxes + previous state) and if I’m not mistaken that will grow exponentially if you add more possible states.
OR
If you use editor scripting, you can have each checkbox represented by a property and an enum holding the main status:
(properties don’t show up in the default inspector unfortunately, but you can set them in a custom editor easily)
private enum State {None, Forward, Reverse, Random};
private State state;
public bool stateForward {
get {
return state == State.Forward;
}
set {
if (value) state = State.Forward;
else {
if (state == State.Forward) state = State.None;
}
}
}
//etc for the other two states
OR
just make it a public enum, which will show up as a dropdown in the inspector, no editor scripting needed.
public enum State {None, Forward, Reverse, Random};
public State state;