using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Net; using System.Net.Sockets; using System.Text; public class sample : MonoBehaviour { TcpClient tcp; NetworkStream ns; // Start is called before the first frame update void Start() { Debug.Log("start"); try { tcp = new TcpClient("127.0.0.1", 8096); ns = tcp.GetStream(); Debug.Log("start ok"); } catch(Exception e) { Debug.Log("connect error"); ns = null; } } // Update is called once per frame void Update() { if (ns == null) { return; } //Debug.Log("update"); var sendbuf = Encoding.UTF8.GetBytes("D"); //データを送信する ns.Write(sendbuf, 0, sendbuf.Length); byte []recvbuf = new byte[256]; ns.Read(recvbuf, 0, 256); string recvtext = System.Text.Encoding.UTF8.GetString(recvbuf); //Debug.Log(recvtext); //Debug.Log("update ok"); string []words=recvtext.Split(','); float[] d = new float[3]; d[0] = float.Parse(words[0]); d[1] = float.Parse(words[1]); d[2] = float.Parse(words[2]); float[] q = new float[4]; q[0] = float.Parse(words[3]); q[1] = float.Parse(words[4]); q[2] = float.Parse(words[5]); q[3] = float.Parse(words[6]); int[] btn = new int[5]; btn[0] = Int32.Parse(words[7]); btn[1] = Int32.Parse(words[8]); btn[2] = Int32.Parse(words[9]); btn[3] = Int32.Parse(words[10]); btn[4] = Int32.Parse(words[11]); this.transform.rotation = new Quaternion(-q[0],-q[1],q[2],q[3]); } }