UnityでUDPデータを受信して、UIのTextに表示をしようと考えているのですが表示することができません。
言語はC#です。
11/10 Debug.Log()については表示が確認できました。
Debug.Log()の内容をTextに表示しようとすると、
get_isActiveAndEnabled can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
というエラーが出ます。
private UdpClient receivingUdpClient; private IPEndPoint remoteIpEndPoint; private Thread thread; public Text text; // port number private int receivePort = 3610; // Use this for initialization void Start() { try { receivingUdpClient = new UdpClient(receivePort); } catch (Exception e) { Debug.Log(e.ToString()); } remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 3610); // start the thread for receiving signals thread = new Thread(new ThreadStart(ReceiveDataBytes)); thread.Start(); // debug Debug.Log("Thread started"); } void ReceiveDataBytes() { while (true) { Debug.Log("Threading inside while"); // NOTE!: This blocks execution until a new message is received Byte[] receivedBytes = receivingUdpClient.Receive(ref remoteIpEndPoint); string receivedStringData = BitConverter.ToString(receivedBytes).Replace("-", string.Empty); Debug.Log("受信データ: " + receivedStringData); text.text = receivedStringData; Thread.Sleep(8); } } void CloseClient() { thread.Abort(); receivingUdpClient.Close(); } void OnApplicationQuit() { CloseClient(); }
よろしくお願いします。

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/11/04 06:20