我有一个非常简单的问题。当我尝试统一构建游戏时出现构建错误。当我在编辑器中运行游戏时,它工作得很好。这是控制台中显示的错误。
Assets\Scripts\Pattern.cs(284,17): error CS0103: The name 'EditorUtility' does not exist in the current context
现在,这是错误引用的代码行:
EditorUtility.DisplayDialog("Great!", "You got the pattern right!", "Next Level!");
最后,如果您认为错误是我没有将正确的东西导入脚本,那您就错了,因为我导入了这个:
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEditor;
有人能帮帮我吗?提前谢谢你。
编辑: 执行此代码:
#if UNITY_EDITOR
EditorUtility.DisplayDialog("Meh", "You got the pattern wrong ):", "Try Again!");
#endif
没用。在构建版本中,它只是不显示消息框,它的行为就好像这一行只是一条评论。有人可以帮忙吗?
最佳答案
您现在出现错误的原因是,Unity 在编译时删除了为它设计的“UnityEditor”命名空间。这就是为什么当您尝试在平台上使用它时,“EditorUtility”将永远不会存在于除 UnityEditor 之外的任何平台上。因为“EditorUtility”在“UnityEditor”命名空间中。
因此,如果您想使用“EditorUtility”完成与在 Unity 编辑器中所做的相同的工作,您应该像他们一样自己实现它。
#if UNITY_EDITOR
EditorUtility.DisplayDialog("Great!", "You got the pattern right!", "Next Level!");
#else
YOUROWNCLASS.DisplayDialog("Great!", "You got the pattern right!", "Next Level!");
#endif
关于c# - 统一构建错误 : The name 'EditorUtility' does not exist in the current context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56813826/