Hi,
I’m about to do something i don’t know is accurate. It works, as well it seem so on the surface, but I’m not sure of the implications this method might have. What I am trying to achieve is to keep adding new instances of a prefab when holding down Shift-key (like you do when plopping out multiple copies of a building in a city-builder).
This is a but pseudo code-ish. In my real code theres a lot more going on, like the building prefab following the mouse, checking for valid ground to place etc, but this demonstrates the issue.
GameObject buildingGO;
void PlopBuilding(string prefabName){
buildingGO = Instantiate( Resources.Load(prefabName), pos, rot ) as GameObject;
}
void PlopBuilding(GameObject go){
buildingGO = Instantiate( go, pos, rot ) as GameObject;
}
void Update(){
if ( Input.GetButtonDown(0) ){
PlopBuilding("Prefab Name");
if( Input.GetKey(KeyCode.LeftShift) ){
PlopBuilding( buildingGO );
}
}
}
So, this will instantiate the instance reference. Will the new instance be fully unique or will this result in some weird connection between the two instances that might result in errors further down?
Thank you!