The type or namespace name `UnityEditor' could not be found

前端 未结 2 1114
攒了一身酷
攒了一身酷 2021-01-19 15:27

Pls help me correct this problem.

Assets/Menu.cs(97,73): warning CS0618: UnityEditor.EditorUtility.GetAssetPath(UnityEngine.Object)\' is obsolete:Use As

相关标签:
2条回答
  • 2021-01-19 15:46

    This happens because classes that are using UnityEditor needs to be put under a folder called Editor: Assets/Editor If you do that, the problem will be gone

    0 讨论(0)
  • 2021-01-19 15:55

    Before using any Unity API, it is very important to check the API namespace. If the namespace is from UnityEditor then it is only meant to work in the Editor only. This is used to make an Editor plugin. You can't use it in a build and it will throw an error when building for any platform.

    According the docs, AssetDatabase and EditorUtility class are from the UnityEditor namespace.

    You have to re-design your game to work without the GetAssetPath function. You can definitely make a game without that function. I can't tell what you are doing but you should look into the Resources class. This will help you load your GameObjects during run-time.

    To solve your current problem,

    Replace

    using UnityEditor;
    

    with

    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    

    Then replace

    objMaterial.textureName = EditorUtility.GetAssetPath(mats[material].mainTexture);
    

    with

            objMaterial.textureName = "";
    #if UNITY_EDITOR
            objMaterial.textureName = EditorUtility.GetAssetPath(mats[material].mainTexture);
    #endif
    

    You can also put your Menu script in a folder in the Assets/Editor directory but please understand that this does not solve the problem that your code won't work in a build. It will only allow your project to build without those errors in your question. The classes from the UnityEditor namespace are only used for Editor plugin.

    0 讨论(0)
提交回复
热议问题