I have been banging my head against a wall for a while. I hope someone might be able to help out with my issue. I’m still new to NGUI and I also have been working in javascript.
I am creating a Muliplayer game and need to get menus to work with NGUI. I have it all working find with the GUI system in unity, I just wanted it to easier to style and such.
I have hosting menu to work fine, you can connect to the server and its all good, its for the joining players where I have the issue at. I have NGUI populating a grid with a label and a button so you can click to join that server.
I can’t figure out how to get the host information for that certain server so you can connect to it.
This is the code i have for populating the list.
for (var element in data)
{
Debug.Log("loadElement");
var name = element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit;
Debug.Log(element);
NGUITools.AddChild(serverTable, serverItem);
serverItem.GetComponent(UILabel).text = name;
serverItem.name = rr.ToString();
//Debug.Log(serverItem.name);
Debug.Log(serverItem.GetComponent(UILabel).text);
NGUITools.AddChild(serverTable, serverButton);
//(serverButton as serverButtonRunner).myInfo = element;
serverButton.GetComponent(serverButtonRunner).myInfo = "hbhhhh";
//yield WaitForSeconds (.5);
serverTable.GetComponent(UIGrid).Reposition();
Debug.Log("Connecting...");
serverButton.SendMessage("receiveMessage", element, SendMessageOptions.DontRequireReceiver);
//create BTN here and the onclick
//NGUITools.addChild();
rr ++;
//Network.Connect(element);
This is all the fail code i have on my button that hasn’t worked.
var targetScript;
private var server:String;
public var myInfo;
function Awake () {
//finds the script that runs the menu
var gameScript = GameObject.Find("menuRunner");
targetScript = gameScript.GetComponent(menuRunner).serverInformation;
//Debug.Log(gameScript.GetComponent(menuRunner).serverInformation);
//targetScript = targetScript.ToString();
}//end of awake
//doesn't work
function receiveMessage(passInfo){
//testInfo = passInfo;
//Network.Connect(testInfo);
//no output
Debug.Log("workihghfdfhjkhfhfghjkhfdfghjng");
}//end of test
function OnClick(){
Debug.Log(targetScript);
Debug.Log("clck");
//this doesn't work
//Network.Connect(targetScript);
//Debug.Log("Connecting...");
}//end of onclick
Anything or suggestions would be grateful.