I’m trying to do rigidbody2D.AddForce, however, it doesn’t work at all. I have a rigidbody2D component attached to the gameobject, but it says that it doesn’t contain a definition for ‘AddForce’, and rigidbody2D isn’t even showing up as something that can be used. It used to work for me a couple months ago, but not anymore.
The “.rigidbody2d” is a shorthand to access the rigidbody2d possibly attached to your object. It was removed in Unity 5. You should use GetComponent() in Start() or Awake() and store the rigidbody2d reference to a field in your class to avoid the perfotmance cost of frequently using GetComponent()