Unity3D不安全代码需要指定`unsafe'命令行选项

or *_*ran 6 c# dll unsafe unity-game-engine

我正在使用Unity3D 4.3并调用DLL我创建的那个.当试图调用它所拥有的唯一函数时,这是:

void GetModelReferences(int &nVertices, float * vertices, int &nTriangles, int * triangles, float * normals, float * uvCoordinates);
Run Code Online (Sandbox Code Playgroud)

团结给了我一个错误:

Unsafe code requires the `unsafe' command line option to be specified
Run Code Online (Sandbox Code Playgroud)

所以在我MonoDevelop打开的时候:Project->Assembly-Csharp options打开unsafe模式.

它减少了部分错误,但最后一个不会消失

Unsafe code requires the `unsafe' command line option to be specified
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

Cod*_*ist 12

转到项目属性页面,然后选中Build复选框Allow unsafe code.这应该可以解决您的问题.

  • 在MonoDevelop中:菜单Project/Assembly-CSharp Options然后Build/General/Allow unsafe (4认同)

us_*_*vid 8

以下是Unity3D 5.3的用途:
- 如果在Unity Build设置 - >播放器设置 - >其他设置中,"API兼容级别"为".Net 2.0",请在Unity资源文件夹下创建一个名为gmcs.rsp的文件,
将以下行添加到文件中:-unsafe
关闭Unity并再次打开它.
- 如果"API兼容级别"为".Net 2.0 Subset",则上述文件名应为:smcs.rsp.

请参阅下面的图片,以查找Unity中"API兼容级别"设置的位置.
在此输入图像描述