转载自:http://download.csdn.net/download/ximenguyu/7639659

一、问题:

Assets/Scripts/SerialPortReciever.cs(7,17):error CS0234: The type or namespace name `Ports' does not exist in thenamespace `System.IO'. Are you missing an assembly reference?

 

本人使用的版本是Unity3D4.2,想在游戏里加串口通信的代码,结果编辑器一直报以上的错误,其实在代码里已经包含命名空间的导入,而且代码编辑器也没有报错:

usingSystem.IO.Ports;

 

二、解决办法:

1、打开Unity工程,在菜单栏中点开File-->Build Setting...

 [Unity3D]Unity3D使用串口的设置_system.data


2、在设置中找到

OtherSetting-->Optimization-->Api Compatibility Level-->.NET2.0

[Unity3D]Unity3D使用串口的设置_system.data_02


 [Unity3D]Unity3D使用串口的设置_syystem.io_03

3、重启Unity,之后就不会有同样的报错了;

 

 

4、如果想在Unity中使用对数据库的操作(System.Data.dll)同样要按以上步骤设置;