- Home /
Build Error
I've tried Reimporting all my assets (Unity only crashes), and the console keeps telling me "Error building Player because scripts had compiler errors" and "Assets/Custom/Scripts/ScoreScript.cs(5,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing an assembly reference?"
What am I doing wrong? Please help!
Thanks
Answer by jdean300 · Dec 03, 2017 at 11:39 PM
Scripts that are included in a build cannot reference the UnityEditor namespace - that is only available to you when running from within the UnityEditor. If you need the editor code in that script, you can set it to only be built while in the editor using preprocessor directives:
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class MyClass : MonoBehaviour {
private void Update() {
#if UNITY_EDITOR
// Code that uses the UnityEditor namespace must be in
// this #if block
#endif
}
}
Your answer
Follow this Question
Related Questions
Built project, now scripts are missing. 2 Answers
How to solve the WebGL UnityEditor.WebGL.ProgressHelper.Show Error 1 Answer
Android build not working (Screen freezing every frame) 0 Answers
error CS0117: `UnityEngine.Graphics' does not contain a definition for `DrawProceduralIndirectNow' 0 Answers