Onclick on runtime buttons

Hi everybody
I´m just finished a scroll bar at runtime, the number of item depends on numbers of folder I have saved for the app. The scroll bar works fine, every item show one image from the folder… but I don´t get that the onclick function works.
How can I do to make the onClick function works on this way?

Thanks in advance!!

OnClick is part of the unityevent system, have a look through this thread, should point you in the right direction

Thanks for the answer. Finally I got the solution. I hab used prefabs to instanciate the buttons, so I drag the script which I want to my prefab, and then to the prefab´s onclick. Now works fine.
Thanks again!!

ah ok, just be aware that prefabs can only consistently link to gameobjects/components within that prefab’s hierarchy. So long as the script you want to call in the onclick is within the prefab you should be fine linking it up in the inspector and then creating the prefab.

If you want to link the button to another gameobject or component in the scene you can’t use that approach and you’ll need to assign the event call through code.