Error when Building Project: Error building Player because scripts have compile errors in the editor

≡放荡痞女 提交于 2019-12-12 12:03:59

问题


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"

Then it points me to this class

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?


回答1:


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.

When Unity is building your project, it ignores any script placed in this folder since it considers them as an Editor script or plugin.

You have three choices:

1.Remove using UnityEditor; from your script.

2.Place your script in a folder called Editor.

3.Use Unity's preprocessor directive to determie when not to compile with using UnityEditor;

You can do that by replacing:

using UnityEditor;

with

#if UNITY_EDITOR 
using UnityEditor;
#endif 

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.



来源:https://stackoverflow.com/questions/42588709/error-when-building-project-error-building-player-because-scripts-have-compile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!