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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

The type or namespace 'NetworkClient' could not be found

Discussion in 'Multiplayer' started by blane1257, Mar 9, 2020.

  1. blane1257

    blane1257

    Joined:
    Dec 5, 2019
    Posts:
    3
    I'm making a multiplayer game and I just copy/pasted the example here: https://docs.unity3d.com/Manual/UNetClientServer.html

    but NetworkClient, NetworkServer, ClientScene, and some others are all either "not found" or "do not exist in the current context"

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6.  
    7. public class NetworkManager : MonoBehaviour
    8. {
    9.     public bool isAtStartup = true;
    10.     NetworkClient myClient;
    11.     void Update()
    12.     {
    13.         if (isAtStartup)
    14.         {
    15.             if (Input.GetKeyDown(KeyCode.S))
    16.             {
    17.                 SetupServer();
    18.             }
    19.             if (Input.GetKeyDown(KeyCode.C))
    20.             {
    21.                 SetupClient();
    22.             }
    23.             if (Input.GetKeyDown(KeyCode.B))
    24.             {
    25.                 SetupServer();
    26.                 SetupLocalClient();
    27.             }
    28.         }
    29.     }
    30.     void OnGUI()
    31.     {
    32.         if (isAtStartup)
    33.         {
    34.             GUI.Label(new Rect(2, 10, 150, 100), "Press S for server");
    35.             GUI.Label(new Rect(2, 30, 150, 100), "Press B for both");
    36.             GUI.Label(new Rect(2, 50, 150, 100), "Press C for client");
    37.         }
    38.     }
    39.  
    40.  
    41.     public void SetupServer()
    42.     {
    43.         NetworkServer.Listen(4444);
    44.         isAtStartup = false;
    45.     }
    46.  
    47.     // Create a client and connect to the server port
    48.     public void SetupClient()
    49.     {
    50.         myClient = new NetworkClient();
    51.         myClient.RegisterHandler(MsgType.Connect, OnConnected);
    52.         myClient.Connect("127.0.0.1", 4444);
    53.         isAtStartup = false;
    54.     }
    55.  
    56.     // Create a local client and connect to the local server
    57.     public void SetupLocalClient()
    58.     {
    59.         myClient = ClientScene.ConnectLocalServer();
    60.         myClient.RegisterHandler(MsgType.Connect, OnConnected);
    61.         isAtStartup = false;
    62.     }
    63.  
    64.     public void OnConnected(NetworkMessage netMsg)
    65.     {
    66.         Debug.Log("Connected to server");
    67.     }
    68. }
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    This may be due to being deprecated and now removed from Unity.
    Check the deprecation thread.

    Mirror seems to be a capable replacement and easy migration.
     
    Joe-Censored likes this.
  3. blane1257

    blane1257

    Joined:
    Dec 5, 2019
    Posts:
    3
    Mirror?
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    This ^^^

    The original Unet HLAPI was removed from the editor and was moved to a package for those still wanting to use it after it was deprecated, and I believe it will become completely unusable starting with 2020.x unless they have changed their time frame.
     
  5. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,333