unity onClick.AddListener code example
Example: unity onclick addlistener
public int index;
private Button myselfButton;
void Start()
{
myselfButton = GetComponent<Button>();
myselfButton.onClick.AddListener(() => actionToMaterial(index));
}
void actionToMaterial(int idx)
{
Debug.Log("change material to HIT on material : " + idx);
}
void Destroy()
{
myselfButton.onClick.RemoveListener(() => actionToMaterial(index));
}