From the course: Unity: Integrating GPS and Points of Interest

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Dynamic button listeners, part 1

Dynamic button listeners, part 1

- Okay guys, let's get this button working now. Now, what I've done is I've dragged back out the prefab so that I can give you a bit of a visual example of what's actually happening here. Now, we have the listing prefab which is getting duplicated as we go down. We have the icon, the first text item, the second text item, and then we have this button which, within it, has its own little text item. Now, what I'm actually trying to do is dynamically change the onclick event. Now, normally you just click add, drag in a function and decide where to go, but the problem is we don't actually know where we want to go until the data has been loaded dynamically on the loop. So, for that what we're going to do is we're going to write some code and add a listener using script so we can dynamically call the function when we click it. Therefore, we're using code to set the onclick event listener. Okay, so how do we do that? Well, first of all we need to get a hold of the button. I'll just delete…

Contents