Attach variables to gameobjects?

I have a bunch of different components, each with their own script which get spawned as child objects to a single main gameObject with a rigidbody. I want to add the mass of each of the child objects to the rigidBody. The mass is stored as a public variable for each object within its script. All of the scripts have different names. Is there a better way to store that kind of data? I don’t want to type out the names of every single sub-objects script and have to do a bunch of if statements etc. just to get a reference to the scripts. Ideally I’d do a foreach component and just pull the variable from the gameobject somehow.

First define a base class with a virtual method in it that returns the mass of that class:

public class MyBaseChildClass : MonoBehaviour {
  private float weight;
  public virtual float GetWeight() {
    return weight;
  }
}

Then make all of your child components derive from that class:

public class YourFirstChildScript : MyBaseChildClass { ... } 
public class YourSecondChildScript : MyBaseChildClass { ... } 
etc. etc.

Now, from your parent class, you can loop through all of the child components and get their weight something like:

MyBaseChildClass[] arrayOfChildren = GetComponentsInChildren<MyBaseChildClass>();
for( int i=0; i< arrayOfChildren.length; i++) {
  sumWeight += arrayOfChildren*.GetWeight();*

}