private IEnumerator InitializeCoRoutine() { _channelURL = _baseURL + _channelID; using (UnityWebRequest request = UnityWebRequest.Get(_channelURL)) { yield return(request.SendWebRequest()); if (request.isNetworkError) { Debug.Log("Error: Could not retrieve websocket URL to connect to chat. " + request.error); } else // Success { string websocketHostsJson = request.downloadHandler.text; ParseWebsocketConnectionInformation(websocketHostsJson); // Find a websocket to connect to. Dictionary <string, string> headers = new Dictionary <string, string>(); _websocket = GetComponent <Websocket>(); _websocket.OnOpen += _websocket_OnOpen; _websocket.OnMessage += _websocket_OnMessage; _websocket.OnError += _websocket_OnError; _websocket.OnClose += _websocket_OnClose; _websocket.Open(new Uri(_websocketURL)); } } }