Здесь у вас есть состояния, поэтому я бы не использовал bool
для этого, а, например, enum
как
public enum ButtonState
{
A, // == 0
B, // == 1
C, // == 2
count // not used as value but simple way to wrap around the maximum value
}
, а затем сделал бы
// initially it is C
ButtonState currentState = ButtonState.C;
public bool a = false;
public bool b = false;
public bool c = false;
public void OnButtonPressed()
{
var index = (int)currentState + 1;
if(index >= (int)ButtonState.count) index = 0;
currentState = (ButtonState)index;
// Now if you really need those bools
a = currentState == ButtonState.A;
b = currentState == ButtonState.B;
c = currentState == ButtonState.C;
// otherwise use the currentState e.g. with a switch
}
Большой Преимущество здесь в том, что если вы позже решите добавить больше возможных состояний, вам нужно всего лишь добавить их в enum
до count
, и вам не придется вносить изменения везде в вашем коде.