I want to get a data from arduino serial monitor and use it in unity
But when I use the below code i get the timeexcpetion error
May I ask what is going wrong?
My unity code
using UnityEngine;
using System.Collections;
using System.IO.Ports;
public class Move : MonoBehaviour
{
SerialPort sp = new SerialPort("COM9", 9600);
void Start()
{
sp.Open();
sp.ReadTimeout = 1000;
}
void Update()
{
Debug.Log("running");
try
{
Debug.Log(sp.ReadLine());
}
catch (System.Exception ex)
{
Debug.Log(ex);
}
}
}
My arduino code
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Hello");
delay(1000);
}