public class NewBehaviourScript : MonoBehaviour
{
public string recievedData;
public GameObject cube;
Vector3 rotationVal;
SerialPort microcontroller = new SerialPort("COM4");
void Start()
{
microcontroller.BaudRate = 9600;
microcontroller.Parity = Parity.None;
microcontroller.StopBits = StopBits.One;
microcontroller.DataBits = 8;
microcontroller.Handshake = Handshake.None;
microcontroller.RtsEnable = true;
microcontroller.DtrEnable = true;
microcontroller.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
microcontroller.Open();
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
Debug.Log("Recieving");
string data = sp.ReadLine();
rotationVal = new Vector3(0, float.Parse(data), 0);
}
void Update()
{
cube.transform.eulerAngles = rotationVal;
}
}