/// <summary> /// Adds the copy of a Component to a GameObject. /// </summary> /// <param name="go">The GameObject that will get the new Component</param> /// <param name="original">The original component to copy</param> /// <returns>The reference to the newly added Component copy</returns> public static Component AddComponent(this GameObject go, Component original) { var c = go.AddComponent(original.GetType()); var originalSerialized = new SerializedObject(original).GetIterator(); var nso = new SerializedObject(c); var newSerialized = nso.GetIterator(); if(originalSerialized.Next(true)) { newSerialized.Next(true); while(originalSerialized.NextVisible(true)) { newSerialized.NextVisible(true); newSerialized.SetValue(originalSerialized.GetValue()); } } nso.ApplyModifiedProperties(); return c; }