Instantiating UI

Hi
I´ve been trying to set up a multiplayer system in a game, and i want to create an ui button for each host that i find. This was my first try:

function ListHosts()
{
	if(hostData)
	{
		for (var i : int = 0; i < hostData.length; i++)
		{
			var Button = Instantiate(button);
			button.Text.Text = hostData*.gameName;*
  •  }*
    
  • }*
    }
    I get following error: “Assets/Scripts/NetworkManagerScript.js(57,32): BCE0019: ‘Text’ is not a member of ‘UnityEngine.GameObject’.”
    So how do i access and change the text of my button. Also, the button isn´t visible after i instantiate it. How do i solve this?
    Thanks in advance!

First have you got

import UnityEngine.UI;

at the top of your script, then you need to GetComponent(“Text”) so…

button.GetComponent("Text").text = hostData*.gameName;*

That said my JS is pretty so if you still get errors let me know.