动画师没有生效

时间:2015-12-16 12:22:22

标签: c# unity3d

在附加到游戏对象的简单脚本中,我有以下内容:

public class Test : MonoBehaviour
{
    private Animator animator;

    void Awake()
    {
        animator = GetComponent<Animator>();

        if (!animator)
        {
            Debug.Log("NO animator!");
        }        
    }
}

但我一直收到NO animator!消息。我错过了什么?

1 个答案:

答案 0 :(得分:2)

我认为我找到了答案here - 您应该将[RequireComponent(typeof(Animator))]应用于Test类:

[RequireComponent(typeof(Animator))]
public class Test : MonoBehaviour
{
    // ...
}