/// <summary> /// Copies all components values. /// </summary> /// <param name="gameObject">The game object.</param> /// <param name="targetGameObject">The target game object.</param> /// <param name="exceptTransform">if set to <c>true</c> [except transform component].</param> public static void CopyAllComponentsValues(this GameObject gameObject, GameObject targetGameObject, bool exceptTransform = true) { if (targetGameObject) { Component[] components = gameObject.GetAllComponents(); for (int i = 0, length = components.Length; i < length; ++i) { Component component = components[i]; if (exceptTransform && component.GetType().FullName == "UnityEngine.Transform") { continue; } component.CopyComponentValues(targetGameObject); } } }