Unity:网络多人游戏

时间:2015-02-26 16:54:57

标签: button unity3d network-programming

我试图这样做,当我点击服务器时,它会被选中,然后我可以在点击后运行代码。

感谢您提供的任何帮助。

function OnGUI() {
    if (!Network.isClient && !Network.isServer) {
        if (joining) {
            if (hostData) {
                scrollPosition = GUI.BeginScrollView(Rect(Screen.width / 4, Screen.height /
                    6, Screen.width / 1.5, Screen.height / 2), scrollPosition, Rect(0, 0,
                    300, 1000 /* hostData.length * 30 */ ));
                GUI.Label(Rect(30, 0, 100, 20), "Game Name");
                GUI.Label(Rect(350, 0, 100, 20), "Server Info");
                GUI.Label(Rect(590, 0, 100, 20), "Player Count");
                GUI.Label(Rect(700, 0, 100, 20), "Password");
                for (var i: int = 0; i < hostData.length; i++) {

                    GUI.Label(Rect(0, 30 + i * 30, 200, 22), hostData[i].gameName);
                    GUI.Label(Rect(160, 30 + i * 30, 500, 22), hostData[i].comment);
                    GUI.Label(Rect(610, 30 + i * 30, 100, 20), hostData[i].connectedPlayers +
                        " / " + hostData[i].playerLimit);
                    if (hostData[i].passwordProtected) {
                        clientPass = GUI.PasswordField(Rect(680, 30 + i * 30, 100, 25),
                            clientPass, "*" [0], 12);
                    }
                    if (GUI.Button(Rect(800, 30 + i * 30, 100, 25), "Join")) {
                        Network.Connect(hostData[i], clientPass);
                    }
                }
                GUI.EndScrollView();
            }

1 个答案:

答案 0 :(得分:0)

我发现了问题。当我改变屏幕分辨率时很明显。只需将屏幕分辨率更改为16x9或16x10即可显示按钮。