I want add a new tag in the Unity editor from script, but give me this error: Code (csharp): Assets/Logic/WayPoints/WayPoint.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? What is the problem?
You haven't posted your WayPoint.cs script, so I don't know what function you are trying to call. My educated guess is that you are trying to use an object whose class is part of UnityEditor. To use a UnityEditor class/object you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script. I hope this helps.
your educated guess is right according the path the error shows. UnityEditor is only available to classes that are within an "Editor" folder
Ah, thanks!, the problem was the folder. I did not know that the script was saved in the Editor folder. Thank you very much.
But how can I reference a script , that is IN the Editor folder , I mean. ScriptName sc; I alwais obtain this The type or namespace name `ScriptName ' could not be found. Are you missing a using directive or an assembly reference?
Same here I saw on another post that the reason for javascript not working on path objects was because my scripts were in the wrong place . I guess I must have just moved the editor scripts at the same time. Thanks
I don't believe that is technically true. My scriptable object uses the UnityEditor directive and is able to implement its own OnInspectorGUI method, which allows me to call this method anywhere I want the scriptable object inspector to be shown. The only problem is when you try to build the game you'll get errors, because UnityEditor cannot be included in a standalone/webplayer,/etc. build. However, I have found that using platform dependent compilation fixes the problem. Simply put Code (csharp): #if UNITY_EDITOR before the using UnityEditor directive and Code (csharp): #endif after it. You will also need to surround your GUI code with these same tags. Hope this helps! Edit: Be careful if surrounding serialized fields with this, as Unity will throw errors when trying to build.
Guys, Does this mean that I can never have a specific Editor functionality in a build? I have a script that uses radio buttons, so I need to add the following as a directive: Code (CSharp): #if UNITY_EDITOR using UnityEditor; #endif But I need the radio buttons to work when I run my app in standalone, and I cannot simply move my script into the Editor folder. How do I resolve this?
Hey I Had the same problem and the way that i got it to work all i did was i add "Using system" at the top of both scripts then you can have both scripts in a scripts folder