问题描述
我有Tiled2Unity插件.当我开始在Unity中构建游戏版本时,无论是独立版本还是其他版本,我都会收到以下错误消息:由于脚本在编辑器中存在编译错误,所以构建Player时出错"
I have the Tiled2Unity plugin. When I begin to build a version of my game in Unity, be it standalone version or anything else,i get the following error, "Error building Player because scripts have compile errors in the editor"
然后它指向我这堂课
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor;
namespace Tiled2Unity
{
public class CircleObject : TmxObject
{
}
}
有人可以帮我找出问题所在吗?
Can someone please help me figure out what is the problem?
推荐答案
您无法构建任何包含using UnityEditor;或class/API的脚本docs.unity3d.com/ScriptReference/Editor.html"rel =" nofollow noreferrer> UnityEditor
命名空间.这就是为什么您应该将包含其中任何一个脚本的任何脚本放在名为 Editor 的文件夹中.
You cannot build any your script that contains using UnityEditor;
or class/API from the UnityEditor
namespace. This is why you should put any script that contains any of these in a folder called Editor.
Unity构建项目时,它会忽略放置在此文件夹中的任何脚本,因为它将它们视为编辑器脚本或插件.
When Unity is building your project, it ignores any script placed in this folder since it considers them as an Editor script or plugin.
您有三种选择:
1 .从脚本中删除using UnityEditor;
.
2 .将脚本放置在名为 Editor 的文件夹中.
2.Place your script in a folder called Editor.
3 .使用Unity的预处理程序指令确定何时不使用using UnityEditor;
3.Use Unity's preprocessor directive to determie when not to compile with using UnityEditor;
您可以通过替换以下内容来实现:
You can do that by replacing:
using UnityEditor;
使用
#if UNITY_EDITOR
using UnityEditor;
#endif
我会选择#2 .为任何编辑器内容创建一个不同的脚本,并将其放置在 Editor 文件夹中.请注意,在构建项目时,Unity将不编译该文件夹中的任何脚本.此文件夹中的脚本只能在编辑器中运行.
I would go with #2. Create a different script for any Editor stuff and place it in the Editor folder. Note that Unity will not compile any script in this folder when building your project. Scripts in this folder are meant to run in the Editor only.
这篇关于生成项目时出错:生成Player出错,因为脚本在编辑器中存在编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!