Type or Namespace Unity.Editor could not be found when trying to build

So, I’ve made a very simple game and plays normally in the editor. But when I try to build ONLY FOR WINDOWS (meaning for other platforms build works fine), I get the error


and the problem is I am not using this Slot.cs script in my project, and the problem refers to the ‘Using Unity.Editor;’ line at the start of the script. How can I fix that?

This is because unity is packing the script into the sources for the build where UnityEditor namespace is not linked.

To solve this, you’ll need to place any script containing the UnityEditor namespace in a folder called Editor. Any files in there will be excluded upon building, and are only meant for editor use.

You can place the Editor folder anywhere you like, altho you might want to look out for the resource folder, but I’m not 100% sure.