Unity 中的命名空间“UnityEngine”中不存在类型或命名空间名称“Windows”

The type or namespace name `Windows' does not exist in the namespace `UnityEngine' in Unity

我的项目运行良好,但是当我制作 APK 文件时,出现错误。

类型或命名空间名称Windows' does not exist in the namespaceUnityEngine'。您是否缺少程序集参考?

找不到类型或命名空间名称“ConfidenceLevel”。您是否缺少程序集参考?

找不到类型或命名空间名称“PhraseRecognizer”。您是否缺少程序集参考?

找不到类型或名称空间名称“PhraseRecognizedEventArgs”。您是否缺少程序集参考?

using UnityEngine.Windows.Speech; <-- 这些地方在我点击顶部错误时显示。

我找到了解决方案:

  1. http://answers.unity3d.com/questions/42719/how-should-i-add-references-to-additional-mono-ass.html.

  2. 资产 --> ReimportAll.

  3. 我添加了#if UNITY_EDITOR,错误消失了,但在 android 上不起作用:https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

但是没用。

有人可以帮助我吗?谢谢大家!

Unity 中的 Windows 命名空间仅用于 Windows PC 构建。它不会也不应该在 Android 上工作。它甚至不应该为 Android 开始构建,您也不应该尝试让 Unity 在 Android.

上使用它

使用 UNITY_STANDALONE_WIN 而不是 UNITY_EDITOR 以防止它为任何其他平台编译。如果您想在 Unity 中进行语音识别,请参阅 post,其中我描述了 类 需要制作我们自己的插件或使用我在该答案中链接的已经制作的资产。