简体   繁体   中英

The type or namespace name 'Animations' does not exist in the namespace 'UnityEditor'

When building the project, an error appears that "The type or namespace name 'Animations' does not exist in the namespace 'UnityEditor'", but Visual Studio does not show errors and all the libraries are connected, I found a solution how to upload the dll file to the Plug-in but could not find where to download dll file UnityEditor. I want to use the Animator Controller in a unity editor.

using UnityEngine;
using UnityEditor.Animations;

public class SkinSetter : MonoBehaviour
{
    public Animator anim;

    public AnimatorController skin1;
    public AnimatorController skin2;
    public AnimatorController skin3;
    public AnimatorController skin4;
    public AnimatorController skin5;
    public AnimatorController skin6;
    public AnimatorController skin7;
    public AnimatorController skin8;



    private void Start()
    {
        SetSkin(PlayerPrefs.GetInt("SkinSelect"));
    }

    public void SetSkin(int ID)
    {
        switch (ID)
        {
            case 1:
                anim.runtimeAnimatorController = skin1;
                break;
            case 2:
                anim.runtimeAnimatorController = skin2;
                break;
            case 3:
                anim.runtimeAnimatorController = skin3;
                break;
            case 4:
                anim.runtimeAnimatorController = skin4;
                break;
            case 5:
                anim.runtimeAnimatorController = skin5;
                break;
            case 6:
                anim.runtimeAnimatorController = skin6;
                break;
            case 7:
                anim.runtimeAnimatorController = skin7;
                break;
            case 8:
                anim.runtimeAnimatorController = skin8;
                break;
        }

    }

}

As mentioned you do not want to use anything related to UnityEditor in your MonoBehaviour at least not in code that shall be executed in your app later.

It is only used to implement some special behaviors while working within the Unity Editor, mostly for custom Inspectors.

This namespace is completely stripped of during the build. So you will get compiler errors when building.


You should make your fields rather of type RuntimeAnimatorController

public RuntimeAnimatorController skin1;
...

and remove any using statement that contains UnityEditor from your script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM