user285372
user285372

Reputation:

Animator not taking effect

In a simple script attached to a game object, I have the following:

public class Test : MonoBehaviour
{
    private Animator animator;

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

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

But I keep getting the NO animator! message. What am I missing?

Upvotes: 2

Views: 71

Answers (1)

Sergii Zhevzhyk
Sergii Zhevzhyk

Reputation: 4202

I think that I found an answer here - you should apply [RequireComponent(typeof(Animator))] to the Test class:

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

Upvotes: 1

Related Questions