Search code examples
c#network-programmingunity-game-enginemultiplayer

Unity 3D 4 Networking issues


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);
                }
            }
        }
    }
}

That's my code. It throws this error: Assets/Network1.cs(15,21): error CS0119: Expression denotes a type', where avariable', value' ormethod group' was expected

I've googled it for a while now and can't seem to get a relevant answer. Any help is appreciated.


Solution

  • if (NetworkPeerType == NetworkPeerType.Disconnected){
    

    this should probably be:

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