【发布时间】:2021-12-17 16:53:38
【问题描述】:
我有一个非常简单的问题。当我尝试统一构建游戏时出现构建错误。当我在编辑器中运行游戏时,它工作得很好。这是控制台中显示的错误。
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
不起作用。在构建版本中,它只是不显示消息框,它的行为就好像这一行只是一个注释。有人可以帮忙吗?
【问题讨论】:
-
您不能在运行时代码中使用编辑器类。将脚本移动到编辑器文件夹。