user3858703
user3858703

Reputation: 111

I am trying to build my game in unity but it is giving me an error

Assets/Scripts/ThirdPersonCamera.cs(3,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?

im so confused on why i am getting this error.....

why is this happening?

Upvotes: 1

Views: 10256

Answers (1)

Smilediver
Smilediver

Reputation: 1808

This is because UnityEditor namespace is available only in editor scripts, that are located in Assets/Editor folder; or if you are running your game in the editor. If you need some functionality while running your game in the editor, you can do this:

#if UNITY_EDITOR
using UnityEditor;
#endif

class Script: MonoBehaviour {
    void Update() {
#if UNITY_EDITOR
        // Editor specific part here
#endif
    }
}

Upvotes: 7

Related Questions