IEnumerator TryConnect()
 {
     while (!client.Connect(_server, _port) && !client.connected)
     {
         Debug.Log("Failed to connect to server.");
         yield return(new WaitForSeconds(1));
     }
     username.transform.parent.gameObject.SetActive(true);
     Debug.Log("Connected to server.");
 }
Beispiel #2
0
    private void connectToServer()
    {
        client = new CustomDataClient <ClientData>(new ClientData(), true);
        client.onDisconnect     += OnServerDisconnect;
        client.onPacketReceived += OnPacketReceived;
        IEnumerator TryConnect()
        {
            while (!client.Connect(_server, _port) && !client.connected)
            {
                Debug.Log("Failed to connect to server.");
                yield return(new WaitForSeconds(1));
            }
            onConnect?.Invoke();
            Debug.Log("Connected to server.");
        }

        StartCoroutine(TryConnect());
    }