Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static T CopyComponent<T>(this T original, GameObject destination) where T : Component
- {
- Type type = original.GetType();
- Component copy = destination.AddComponent(type);
- var fields = type.GetFields();
- foreach (System.Reflection.FieldInfo field in fields)
- field.SetValue(copy, field.GetValue(original));
- return copy as T;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement