Mutator method to change multiple bool variables?

Hi,

I’m trying to make a method to change the state of whichever boolean variable’s name(or index etc depending on easiest way to do it) is parsed into the method.

For example (The aim is to make situation1 in the second class true).

'Extract of First Class

globalStats.GetComponent<GlobalStats>().ChangeBoolean(situation1);

'Extract of Second Class
private bool situation1;
private bool situation2;
private bool situation3;

public void changeBoolean(string boolName)
{
???
boolName = true;
???
}

But that obviously comes up with a “can’t convert string to bool” error.

I also tried to make an array containing all boolean variable names and just parsing in an index. But that encounters similar conversion issues.

How should I handle the updating of these boolean variables (Avoiding the use of 50+ if statements)?

Hi.

Can’t you just pass it as a bool parameter??

public void changeBoolean( bool boolName )
{
    // if negative => sets to positive. vice versa.
    boolName = !boolName;
}

Sorry for the poorly explained question.

The solution was very simple once I had another look at the unity manual.

Simply

globalStats.GetComponent<GlobalStats>().situation1 = true;

No use of mutator methods required :D.