To understand how you can use Uduino with existing libraries, two tutorials on this website explains the basic concept.
The process to use Uduino with custom libraries is fairly simple:
If you need inspiration, have a look at the projects!
TLDR; Remove the
delay from your code !
If you use
delay() in your sketch, it will pause your sketch for some ms. Hence the connection between Unity and Arduino will not work smoothly; for instance, a message sent will be waiting in your serial buffer.
If you want to use delay, you should use the function
uduino.delay(), that works similarly to the Arduino delay function but maintain the Uduino connection open.
Similarly, you should know that every
Serial.print() that you use in your loop is susceptible to be read by Unity. hence I recommend to remove unnecessary print and only use
uduino.print()when you want to send a variable.