Unity button with attached script cannot detect function after adding "ref"

Viewed 31

After attaching it to unity UI button, the function cannot be found under click(). However, if i were to remove the ref, i can see it. How can i solve this?

public bool bool1 = false;
public bool bool2 = false;
public bool bool3 = false;
....
public bool bool100 = false;

public void ChangeBool(ref bool a)
{
    a = true;
}

My goal is to create a single function for many buttons which will change each individual boolean each.

I understand that i can create 100 functions for 100 booleans but my worries is that the script will get very long.

1 Answers

In inspector you can't add a method with parameter

btn.onClick.AddListener(() => { Function(param); OtherFunction(param); })

With lambda expression you can add that method in code btn is button for sure.

Related