Set bool to be active only when a button and another bool are set
I'm trying to set a bool to be active only when another bool is active along with a button press. The thing is, I want to be able to use the same button for both, but as it is now, the second boolean is automatically set to true when the first one is. I want to be able to press the A button once to set the first boolean to true, and then press A to set the second one to true, only when the first is true.
if (P1ColorChoose == true && Input.GetKeyDown(KeyCode.A))
{
P1Confirm = true;
}
This is the code I'm using currently.
Answer by rage_co · Jul 27, 2021 at 04:31 AM
It's really simple
if (Input.GetKeyDown(KeyCode.A))
{
if(!P1ColorChoose)
{
P1ColorChoose = true;
}
else
{
P1Confirm = true;
}
}
Just check whether the P1ColorChoose bool is true or not after the button press and decide the course of action.
Just to clarify, since P1ColorChoose is a boolean, P1ColorChoose is essentially the same as comparing it to true and !P1ColorChoose is the same as comparing it to false. Hope this helps!