Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Unity throws an error when I use the "Network" class

Discussion in 'Multiplayer' started by The-Game-Master, Aug 24, 2014.

  1. The-Game-Master

    The-Game-Master

    Joined:
    Aug 6, 2014
    Posts:
    54
    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 a `variable', `value' or `method group' was expected


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

    The-Game-Master

    Joined:
    Aug 6, 2014
    Posts:
    54
  3. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    You need to check the 'Network.peerType' and not the NetworkPeerType enum.
    Also please post code using the code tags so we can read properly.
     
  4. The-Game-Master

    The-Game-Master

    Joined:
    Aug 6, 2014
    Posts:
    54
    Ok. Thanks.