error cs0236 field initializer cannot reference a nonestatic field, method or property

public class UnitGoal : MonoBehaviour {

	BrainHealth BH = gameObject.GetComponent<BrainHealth>();

	void OnTriggerEnter(Collider c) {
		Destroy(c.gameObject);
	}
	
}

please help

Like the error message says, you’re trying to initialise BH with a value returned from GetComponent(), which is not static.

public class UnitGoal : MonoBehaviour {
 
    BrainHealth BH;

    void Start() {
        BH = gameObject.GetComponent<BrainHealth>();
    }

    void OnTriggerEnter(Collider c) {
        Destroy(c.gameObject);
    }
}