I could not be more baffled. I cannot get a rigidbody component

I made a capsule and added a rigidbody component. I hit play and it collides with the box below it. However, when I add this to the C# script I get an error

public Rigidbody rb = GetComponent();

Assets/PlayerMove.cs(10,24): error CS0236: A field initializer cannot reference the nonstatic field, method, or property `UnityEngine.Component.GetComponent<UnityEngine.Rigidbody>()’

Hi,

Give this a try…

public Rigidbody rb;

void Awake () {
rb = GetComponent<Rigidbody>();
}
2 Likes