A better approach would be to use UnityEditorInternal namespace:
UnityEditorInternal.ComponentUtility.CopyComponent(componentToCopy);
UnityEditorInternal.ComponentUtility.PasteComponentAsNew(targetGameObject);
You can also use PasteComponentValues instead of PasteComponentAsNew.
↧