Mobile 2D LAN Game

Okay so I’m trying to make a mobile LAN pong game. I’ve made a menu system using the new UI but there don’t seem to be any help videos that implements this feature yet. Ive been getting off okay so far, until I got to the part where the games currently up on the network come up. I know i have one running, but it doesn’t display it. Here is my code.
#pragma strict

var gameName : String = "Pong2D Multiplayer";

private var btnX : float;
private var btnY : float;
private var btnW : float;
private var btnH : float;

function Start(){
	btnX = Screen.width * 0.05;
	btnY = Screen.width * 0.05;
	btnW = Screen.width * 0.1;
	btnH = Screen.width * 0.1;
}

private var refreshing :  boolean;

private var hostData : HostData[];

function startServer(){
	Network.InitializeServer(32,25001, !Network.HavePublicAddress);
	MasterServer.RegisterHost(gameName, "Server","This is another Player's server!");
}

function refreshHostList(){
	MasterServer.RequestHostList(gameName);
	refreshing = true;
}

function Update(){
	if(refreshing){
		if(MasterServer.PollHostList().Length > 0){
			refreshing = false;
			Debug.Log(MasterServer.PollHostList().Length);
			hostData = MasterServer.PollHostList();
	}
}
}

function OnServerInitialized(){
	Debug.Log("Server Started!");
}

function OnMasterServerEvent(mse:MasterServerEvent){
	if(mse == MasterServerEvent.RegistrationSucceeded){
		Debug.Log("Registered Server!");
	}
}

function onGUI(){
	
Debug.Log("Refreshing Hosts");
refreshHostList();

if(hostData){
	for(var i:int = 0; i < hostData.length; i++){
		if(GUI.Button(Rect(Screen.width - 100,0,100,50), "Pong Game")){
			Network.Connect(hostData*);*
  • }*
  • }*
  • }*
    }

Okay. Remove the Debug.Log("Refreshing Hosts"); refreshHostList(); line. This makes your game refresh host list every frame. Instead, run refreshHostList(); on a GUI Button.

I have a video that will build a menu dynamically in the new UI. Check it out here

In essence you want a prefab for the button. Then you Instantiate each button in a loop, and add a listener to call the function you are after.

Note that you should not be using OnGUI with the new UI.