usingUnityEngine;usingSystem.Collections;usingSystem.IO.Ports;publicclasstest2:MonoBehaviour{inti=1;SerialPortstream=newSerialPort("COM3",115200);//Set the port (com4) and the baud rate (9600, is standard on most devices)intspeed=30;intfactor=1000;floatposFromSerial;voidStart(){stream.Open();//Open the Serial Stream.//StartCoroutine(Whatever() );//InvokeRepeating ("updateserial", 2, 0.5f);}// Update is called once per framevoidUpdate(){//if (Input.GetKeyDown ("left")) {//transform.position=rigidbody.transform.position//}//if (Input.GetKeyDown("space"))//{ //string s = i.ToString();//stream.Write(s);//stream.BytesT;//i+=1;//}//if (Input.GetKey("space"))//{ //string s = velo.ToString ();//string s = velo.ToString ();//stream.Write("-"+s);//}}voidFixedUpdate(){//rigidbody.AddForce(mouvment * speed * Time.deltaTime);//gameObject.transform.Translate (mouvment);//rigidbody.MovePosition (rigidbody.position + mouvment);//float velo = Mathf.Round (rigidbody.velocity.magnitude)+1; //string s = velo.ToString ();//stream.Write("2");//StartCoroutine (Wait(2.0f));//yield return new WaitForSeconds(1.0f);//StartCoroutine(Whatever());}voidOnGUI(){floatspeedm=Mathf.Round(rigidbody.velocity.magnitude);//float velo = Mathf.Round (rigidbody.velocity.magnitude)+1; GUI.Box(newRect(10,10,200,90),"Measurements");//GUI.Label(new Rect(20,40,180,20), speedm + " / " + velo + " / serial: ");floatmouveHorizontal=Input.GetAxis("Horizontal");floatmouveVertical=Input.GetAxis("Vertical");stringserialR=stream.ReadLine();posFromSerial=float.Parse(serialR);floatvelo=Mathf.Round(rigidbody.position.x/factor);Vector3mouvment=newVector3(posFromSerial/factor,0,mouveVertical);Vector3mouvmentrelatif=rigidbody.position-newVector3(posFromSerial/factor,0,mouveVertical);rigidbody.MovePosition(mouvment);}//IEnumerator Whatever()//{//float timeToWait = 10;//yield return new WaitForSeconds(timeToWait);//////}//void updateserial(){//float velo = Mathf.Round (rigidbody.velocity.magnitude)+1; //string s = velo.ToString ();//stream.Write("2");//}}