xxxxxxxxxx
// First, get a reference to the game object you want to add the component to
GameObject gameObject = // Enter your game object reference here;
// Add the desired component to the game object
gameObject.AddComponent<ComponentName>(); // Replace ComponentName with the actual name of the component you want to add
xxxxxxxxxx
//Use the AddComponent<T>() Method to add a component to your gameobject
GameObject gameObject;
gameObject.AddComponent<BoxCollider>(); //Component has to be an actual Unity component