how to add a component to a gameobject unity code example
Example: c# addcomponent
// Consider an existing GameObject, gameObj
Rigidbody addedComp = gameObj.AddComponent<Rigidbody>() as Rigidbody;
// You can also add custom components by class name