Check out example codes for "unity onclick addlistener". It will help you in understanding the concepts better.
Code Example 1
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));
}
Learn ReactJs, React Native from akashmittal.com