Quantcast
Channel: Answers for "Editor Wizard: Copy Existing Components to Another GameObject"
Viewing all articles
Browse latest Browse all 8

Answer by SimTex

$
0
0

Use reflection.

Component new_component = gameObject.AddComponent(old_component.GetType());
foreach (FieldInfo f in old_component.GetType().GetFields())
{
  f.SetValue(new_component, f.GetValue(old_component));
}

Viewing all articles
Browse latest Browse all 8

Trending Articles