ComponentExtensions

This class allows you to copy Unity components from certain gameobjects, so you can add these copied components onto other gameobjects if needed.

Available methods

public static T GetCopyOf<T>(this T comp, T other) where T : Component

This extension method creates copy of given component.

Example:

var rb = firstGO.GetComponent<Rigidbody>();
secondGO.AddComponent<Rigidbody>().GetCopyOf(rb) as Rigidbody;

public static T AddComponent<T>(this GameObject go, T toAdd) where T : Component

This extension method copies component toAdd and adds it onto given gameobject.

Example:

var rb = firstGO.GetComponent<Rigidbody>();
secondGO.AddComponent(rb);

Last updated