Instantiating a button and modifying its script?

Hello all,

Basically what I want to do is instantiate around 100 buttons, but each have a different option pulled from a WWW.

What I was going to do is make a button prefab and set a script with it that holds the buttons ID and text. How would I edit the ID via script for each one? I’m familiar with the WWW part and instantiating it.

Put the button text and WWW target in string variables, then set the strings when you construct the buttons at runtime.

I’m not sure what you mean. I can construct the buttons with their data just fine, but when someone clicks the button I want it to do different things.

For example it will load 100 different images, and when a user clicks one it will respond by displaying the appropriate data for that image.

Erm, I’m not sure what you are trying to do here, then.

A good example would be a mail box. For each message for the player found in the database I want to instantiate a subject line and also a view button for each message. When the player clicks the view button beside the subject, how do I tell a new WWW to get the message text to display?

This is pretty much it.

Have a variable on each button. Set the variable to whatever is appropriate when you instantiate it. Then take the appropriate action when you click.

This video is somewhat tangential to your question, but it may help.

https://www.youtube.com/watch?v=0_QQtCyQ8aI

1 Like

That works great! Thank you so much!!