I am using Arduino Uno and Unity 3.4.1, and am trying to communicate them with each other. But the serial monitor is not printing anything. In Unity console i am able to see the logged value "Yes". Here is the arduino IDEs code:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
String receivedData = Serial.readStringUntil('\n');
Serial.println(receivedData);
}
Serial.println("abs");
}
and the output:
And here is the C sharp script for Unity:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports;
using System.Threading;
public class controller8 : MonoBehaviour
{
// Start is called before the first frame update
public string portName = "COM3";
public int baudRate = 9600;
private SerialPort serialPort;
void Start()
{
serialPort = new SerialPort(portName, baudRate);
serialPort.Open();
}
// Update is called once per frame
void Update()
{
serialPort.WriteLine("Yes");
Debug.Log("Yes");
}
}
Here is the output:
Edit : Have to clarify that this code works when i close Unity and run it. And also i am able to send data to Unity using serial print, but not receive from Unity.