Question by
SergioCut · Feb 20, 2021 at 03:37 AM ·
unity 5buttonsassign-variable
How can I use a ref bool when I get: "cannot use ref or out parameter inside an anonymous lambda expression, or query expression"?
I'm trying to create a function that takes the name of a bool and set it true, and assign it to a button via script. The result should be something like this:
bool myBool;
GameObject button;
void assignAndActivateBool(ref bool nameOfTheBool)
{
Instantiate(button, GameObject.Find("Canvas").transform, false);
button.GetComponent<Button>().onClick.AddListener(() => nameOfTheBool = true);
}
void createButton()
{
assignAndActivateBool(ref myBool);
}
I get this error using "nomeOfThebool": Cannot use ref or out parameter inside an anonymous method, lambda expression, or query expression.
I'm really new at coding. I hope my explanation is compriensible.
Comment