I have class "Button" with function
public void SetOnClickListener(UnityAction listener)
{
btn.onClick.AddListener(listener);
}
I have class "A" with fllow code
void D()
{
Button btn = new Button();
btn.SetOnClickListener(new UnityAction(SomeFunction));
}
public void SomeFunction()
{
Debug.Log("Some Function was called!");
}
And it doesn't work. But if I do next change->
void D()
{
Button btn = new Button();
btn.SetOnClickListener(new UnityAction(SomeFunction));
}
public static void SomeFunction()
{
Debug.Log("Some Function was called!");
}
All work correctly. Why I must use static and can I not use it?
statickeyword is about general programming. Official documentation of static or this question might be helpful and/or some basic programming tutorials. \$\endgroup\$staticwas, he would understand what is wrong and how to fix it. Seeing the answer (covering the general programming aspect), it is less detailed version of those in linked SO question, and I am not sure if that is helpful for future references... but I guess having duplicate questions between sites does not hurt neither. \$\endgroup\$