- Home /
Network button not displaying
Hello most of this is working the only problem is when i go to display the client connection button, it does not display anything. I dont know what is wrong here it looks that same as the other buttons. and the button does display when I tested the position of the button so the code seams right. It just does not display in the hostdata if statement. any help would be appreciated.
private var hostData: HostData[];
private var refreshing : boolean;
var bX : float;
var bY : float;
var bW : float;
var bH : float;
function Start()
{
bX = Screen.width * 0.1;
bY = Screen.width * 0.1;
bW = Screen.width * 0.1;
bH = Screen.width * 0.1;
}
function Update()
{
if(refreshing)
{
if(MasterServer.PollHostList().Length > 0)
{
refreshing = false;
Debug.Log(MasterServer.PollHostList().Length);
//hostData = MasterServer.PollHostList();
}
}
}
function startServer()
{
Network.InitializeServer(32,25000,!Network.MovePublicAddress);
MasterServer.RegisterHost(gameName, "Batman Driver game", "This is a test");
}
function OnServerInitialized()
{
Debug.Log("Server initilized");
}
function OnMasterServerEvent(mse:MasterServerEvent)
{
if(mse == MasterServerEvent.RegistrationSucceeded)
{
Debug.Log("Server Registered");
}
}
function refreshHostList()
{
Debug.Log("Refreshing");
MasterServer.RequestHostList(gameName);
refreshing = true;
}
function OnGUI()
{
if(!Network.isClient && !Network.isServer)
{
if(GUI.Button(Rect(bX, bY, bW, bH), "Start Server"))
{
Debug.Log("Server Start");
startServer();
}
if(GUI.Button(Rect(bX, bY * 1.2 + bH, bW, bH), "Refreash Host"))
{
refreshHostList();
}
//this works
//GUI.Button(Rect(bX * 1.5 + bW, bY * 1.2 + (bH * 0), bW *3 , bH * 0.5), "Game test");
if(hostData)
{
for(var i: int = 0; i < hostData.lenght; i++)
{
if(GUI.Button(Rect(bX * 1.5 + bW, bY * 1.2 + (bH * i), bW *3 , bH * 0.5), hostData[i].gameName))
{
Network.Connect(hostData[i]);
}
}
}
}
}
Answer by Jake.OConnor · Dec 12, 2012 at 06:34 PM
Well if this is the unedited code, then it's not displaying because you commented out the line which assigns a value to hostData.
//hostData = MasterServer.PollHostList();
That should probably not be commented out if you want to use hostData.
Dang i feel stupid I been looking over the code for too long. Thanks a lot.
Your answer
![](https://koobas.hobune.stream/wayback/20220613085330im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Button To Web Address 1 Answer
GUI.Button background image 0 Answers
networkview + GUI 2 Answers
gui text button dont work 1 Answer
GUI click through? 3 Answers