问题描述

在使用OpenCV For Unity插件时报错 “Assets\OpenCVForUnity\Examples\Advanced\AlphaBlendingExample\AlphaBlendingExample.cs(530,17): error CS0227: Unsafe code may only appear if compiling with /unsafe. Enable “Allow ‘unsafe’ code” in the inspector for ‘Assets/OpenCVForUnity/EnoxSoftware.OpenCVForUnity.asmdef’ to fix this error.”
在这里插入图片描述

解决方法

这里提供两种方式修改:

1.Tools入口修改

在窗口上侧的 Tools > OpenCV For Unity > 勾选Use Unsafe Code。
如下图:
在这里插入图片描述

不过可能会没有该入口的情况,则使用方法2.

2.修改asmdef文件

.asmdef文件是程序集定义文件(Assembly Definition File),这个方法在报错提示中也有。
在Assets/OpenCVForUnity/EnoxSoftware.OpenCVForUnity.asmdef 路径下的文件进行修改,选中文件后,在Inspector窗口中勾选Allow ‘unsafe’ Code选项,Apply。

在这里插入图片描述

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐