Advertisement
obernardovieira

[Unity3D] Network client and server connection

Feb 3rd, 2017
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Networking;
  3.  
  4. public class Scores : MonoBehaviour
  5. {
  6.     NetworkClient myClient;
  7.  
  8.     public void SetupClient()
  9.     {
  10.         myClient = new NetworkClient();
  11.         myClient.RegisterHandler(MsgType.Connect, OnConnected);
  12.         myClient.Connect("127.0.0.1", 4444);
  13.     }
  14.  
  15.     public void OnConnected(NetworkMessage netMsg)
  16.     {
  17.         Debug.Log("Connected to server");
  18.     }
  19.  
  20.     public void OnPlayerConnectMessage(NetworkMessage netMsg)
  21.     {
  22.         Debug.Log("New player connected!");
  23.     }
  24.  
  25.     void Start ()
  26.     {
  27.         NetworkServer.Listen (4444);
  28.         NetworkServer.RegisterHandler (MsgType.Connect, OnPlayerConnectMessage);
  29.  
  30.         SetupClient ();
  31.     }
  32.  
  33.     void Update ()
  34.     {
  35.  
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement