【问题标题】:Unity 3D 4 Networking issuesUnity 3D 4 网络问题
【发布时间】:2014-08-23 23:28:11
【问题描述】:
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 avariable',value' ormethod 组是预期的

我已经用谷歌搜索了一段时间,但似乎无法获得相关答案。 任何帮助表示赞赏。

【问题讨论】:

    标签: c# networking unity3d multiplayer


    【解决方案1】:
    if (NetworkPeerType == NetworkPeerType.Disconnected){
    

    这应该是:

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

    【讨论】:

    • 这不会产生至少一个警告吗?如果编译器没有抱怨,我会感到惊讶。
    • 它确实抛出了一个错误,我无法运行游戏。
    • ob 是的,你在问题中提到了这一点,抱歉 :)
    猜你喜欢
    • 2015-06-12
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-17
    相关资源
    最近更新 更多