using UnityEngine; using System.Collections; using System.IO.Ports; public class test2 : MonoBehaviour { int i = 1; SerialPort stream = new SerialPort("COM3", 115200); //Set the port (com4) and the baud rate (9600, is standard on most devices) int speed = 30; int factor = 1000; float posFromSerial; void Start () { stream.Open(); //Open the Serial Stream. } // Update is called once per frame void Update () { // if (Input.GetKey("space")) // { float velo = Mathf.Round (rigidbody.position.x/factor); string s = velo.ToString (); //stream.Write("-"+s); // } } void FixedUpdate(){ float mouveHorizontal = Input.GetAxis("Horizontal"); float mouveVertical = Input.GetAxis("Vertical"); Vector3 mouvment = new Vector3(posFromSerial/factor, 0, mouveVertical); Vector3 mouvmentrelatif = rigidbody.position - new Vector3(posFromSerial/factor, 0, mouveVertical); // ça c'est pour bouger la bouboule rigidbody.MovePosition (mouvment); //StartCoroutine (Wait(2.0f)); //yield return new WaitForSeconds(1.0f); //StartCoroutine(Whatever()); } }