Unity 3D 4网络问题

时间:2014-08-23 23:28:12

标签: c# networking unity3d multiplayer

using UnityEngine;
using System.Collections;

public class Network1 : MonoBehaviour {
    // Use this for initialization
    void Start () {
    }

    // Update is called once per frame
    void Update () {
    }

    void OnGUI() {
        Debug.Log ("OnGUI()");
        if (NetworkPeerType == NetworkPeerType.Disconnected){
            if (GUI.Button (new Rect(10, 30, 120, 20), "Join a game")){
                Network.Connect("127.0.0.1", 25001);
            }
            if (GUI.Button (new Rect(10, 50, 120, 20), "Host a game")){
                Network.InitializeServer(32, 25001, false);
            }
            else if (Network.peerType == NetworkPeerType.Client){
                GUI.Label(new Rect(10, 10, 300, 20), "Status: Connected as a Client");
                if (GUI.Button (new Rect(10, 30, 120, 20), "Leave lobby")){
                    Network.Disconnect(200);
                }
            }
        }
    }
}

那是我的代码。它抛出此错误: Assets / Network1.cs(15,21):错误CS0119:表达式表示type', where a变量',value' or方法组'预计

我现在用Google搜索了一段时间,似乎无法得到相关的答案。 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

if (NetworkPeerType == NetworkPeerType.Disconnected){

这应该是:

if (Network.peerType == NetworkPeerType.Disconnected){