Best way to add specific child objects to a list.

In my game, I have spaceships. These spaceships have one to many child objects, some of which contain weaponsets. I would like to know the best way to have only the objects that have weaponset scripts attached, added to a list automatically (ie during game play if weapon is added/removed ect)

Ideally in c# please and thankyou.

This question is pretty vague. The best data structure to use depends on the data itself: what does it mean, how will it be used? The simplest thing you could do is list all components of type X using GetComponentsInChildren, then iterate over the list according to whatever criteria you have in mind.

Maybe you want a List, for flexibility.

Maybe you want a HashSet, to make sure entries are only present once.

Maybe you want a Dictionary, for rapid lookups.

Maybe you want a jagged or multi-dimensional array, to represent some columnar or grid setup.

There are many data structures you could use. A question as open-ended as this is really more suited to the forums.

Failing that, you can always check the Unity wiki: Which Kind Of Array Or Collection Should I Use?