I'm trying to get my arduino working with Unity but I keep getting errors about my port not being open.
Here's my Unity code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports;
public class movingTest : MonoBehaviour
{
SerialPort data_stream = new SerialPort("/dev/cu.usbmodem142401", 19200);
public string receivedstring;
public GameObject test_data;
public Rigidbody rb;
public float sensitivity = 0.01f;
public string[] datas;
// Start is called before the first frame update
void Start()
{
data_stream.Open();
}
// Update is called once per frame
void Update()
{
receivedstring = data_stream.ReadLine();
string[] datas = receivedstring.Split(',');
rb.AddForce(0, 0, float.Parse(datas[0])*sensitivity * Time.deltaTime, ForceMode.VelocityChange);
rb.AddForce(float.Parse(datas[1]) * sensitivity * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
transform.Rotate(0, float.Parse(datas[2]), 0);
}
}
It shows a red squiggly line under "using System.IO.Ports" (The type of namespace name 'Ports' does not exist in the namespace 'System.IO' (are you missing an assembly reference?))
There's also another red squiggly line under "SerialPort" (The type of namespace name 'SerialPort' could not be found (are you missing a using directive or an assembly reference?))
My Api Compatibility is .NET Standard 2.0
When the game runs on Unity, the only error I get is "Specified port is not open".
Here's how my ports look like. Every youtube tutorial I watched had ports like "COM4" or something, while I get this weird /dev/cu.usbmodem... monstrosity. I think this is my main problem.
Can anyone tell me what I'm doing wrong?


