I have a base class for all creatures that all share some variables.
public class Creature : MonoBehaviour {
[HideInInspector] public Rigidbody rb;
[HideInInspector] public Animator anim;
[HideInInspector] public Health health;
public LayerMask groundLayer = 1;
public bool isGrounded;
void Awake () {
rb = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
health = GetComponent<Health>();
}
void FixedUpdate(){
isGrounded = Physics.Raycast(transform.position + (Vector3.up * 0.02f), Vector3.down, 0.2f, groundLayer);
}
}
Subclasses like Player/Enemy/NPC therefore derive from Creature so all the variables are accessable, but when I want to use rb/anim/health I always get a NullReferenceException.
I don’t get it since I initialized the components in the base class.