- Home /
Question by
cobrarep · Jun 02, 2016 at 03:59 PM ·
scripting problembuttontextinstantiate prefabrenaming
create a button with name and text for every game object with tag
I have 10 game objects called "marker1" through "marker10". For each of these game objects i want to create a button whose name and text is the same as the name of the game object.
I have the following code so far
public class buttongenerator : Monobehaviour {
public GameObject buttonprefab;
public GameObject scrollbox;
void Start () {
GameObject [] markerlist = GameObject.FindGameObjectsWithTag ("Marker");
var markername = gameObject.transform.name;
for (var i = 0; i < markerlist.Length; i++) {
GameObject newbutton = Instantiate (buttonprefab) as GameObject;
newbutton.transform.SetParent (scrollbox.transform);
//All the code works up to here. My problem is renaming the buttons and changing the text to be the name of the marker.
I have tried using newbutton.guiText = markername [i]
and newbutton.name = markername [i]
but it doesn't change the name or text of the generated buttons.
Any ideas?
Comment