How to write a function that sets a bool

Hi!
I was trying to write a function that could switch other bools, but it doesn’t seem to work. Could someone explain what I’m doing wrong? Is it not possible to pass what bool to set in a function?

Thanks in advance!

public bool MyBool;

void Start()
{
	SomeFunctionSettinggBools(MyBool);
}

public void SomeFunctionSettinggBools( bool BoolToSet)
{
	if (someCondition))
		BoolToSet= true;
	else
		BoolToSet= false;
}

Basic variable types are usually what are called value-types, which differ from others called reference-types. Booleans are value-types, so when you pass them into a function you are actually passing a copy of that value – not the value itself. In C# you can specify how that argument is treated with the ref keyword:

public void SomeFunctionSettinggBools( ref bool BoolToSet)
 {
     if (someCondition))
         BoolToSet= true;
     else
         BoolToSet= false;
 }

which is then called by

SomeFunctionSettinggBools(ref MyBool);

To do this, you will need to pass the variable in by reference.

public void SomeFunctionSettinggBools( ref bool BoolToSet)
 {
     if (someCondition))
         BoolToSet= true;
     else
         BoolToSet= false;
 }

Without the ref keyword that I’ve added, the function has its own local copy of the variable, and so the changes you make in the function do not impact on the variable that the caller passed in.