Hey guys, I’m hoping someone on here might have some experience with Unity2D/4.6 UI elements. I’m building a system that procedurally generates random items, and loads them into a storefront system. I’ve got a barebones prefab which the script is filling - stats, image, etc etc. The problem is in filling the method to be called via the button’s OnClick method.
Currently I’ve got the following script on it’s parent container; note that the method being passed through is just a Debug.Log call, to see if the button is actually working.
```csharp
-
Transform purchaseButton = newItem.transform.FindChild(“Purchase”);
if (purchaseButton != null) {
Debug.Log(“found button”);
UnityEngine.Events.UnityAction action1 = () => { Debug.Log (“Got a button click”); };
purchaseButton.GetComponent().onClick.AddListener(action1);Transform buttonText = purchaseButton.transform.FindChild("Text"); buttonText.GetComponent<Text>().text = "Purchase " + itemNames;}*
```
Altering the buttonText works fine and as expected; and obviously, I’ve no problem in finding the button object via the script. There’s no compile-time, or run-time errors to speak of. However, try as I may, I can’t pass through the new action into the onClick listener.
Can anyone lend me a hand, or some advice on this? I’d very much appreciate it ![]()