Reputation:
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
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