Hey guys, I’m trying to copy a component from a gameobject in my Project/Plugins folder, to another/different gameobject in my Hierarchy.
I can do this the ‘normal’ way, instantiating the prefab with the component I want and then extracting it. But I’m looking for a more ‘cleaner’ aproach. I need to use a static method, wich loses all references to mohobehaviours but can be called from anywhere.
So lets assume I have this: Project/Plugins/Crazy/PrefabWithTheComponent, and this prefab has a component named ‘CrazyComponent’, wich has references to other prefabs. I want, at runtime, to copy/instantiate this component and attach it to the main camera. Is it even possible?
PseudoCode sample:
public static CrazyComponent MoveComponentAround()
{
CrazyComponent comp = FindObjectWithComponent("Project/Plugins/Crazy/PrefabWithTheComponent")
CrazyComponent mainCamComp = Camera.Main.AddComponent<CrazyComponent>();
mainCamComp = comp; //somehow copy the references from the prefab to the new instance
}
Does it make any sense? Or am I typing jiberish?