ina
1
Is it possible for uGUI buttons to access onclick methods that are static? It seems like only instances do not show up as “missing”
Kiwasi
2
Currently no. You have to use an instance method as a wrapper to call the static method.
I found a work around to this that kind of simulates static methods:
Add your script onto a gameobject and make it a prefab. Now you can select the prefab in your button onclick and it will work just fine but you still need to use non static methods.
I really don’t understand though why, even today, those static functions are not supported. Would seem like a no-brainer to me.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
public class BtnForStatic : MonoBehaviour {
private Button btn;
// Use this for initialization
void Start () {
btn = GetComponent<Button>();
}
public void AddBtnListener(UnityAction call)
{
btn.onClick.AddListener(call);
}
}