public AreaBuilding CreateAreaBuilding(GridCell minGridCell, GridCell maxGridCell, Vector2 size, int type) { // setup for selection object Vector3 oldPosition = selection_object.transform.position; SetupPositionAndSize(minGridCell.gridPosition, size); selection_object.transform.position = UpdateSelectionObject(minGridCell, maxGridCell, size); // instantiate new gameObject and then position and parent it GameObject new_go = (GameObject)Instantiate(selection_object); new_go.transform.position = selection_object.transform.position; new_go.transform.position = new Vector3(selection_object.transform.position.x, selection_object.transform.position.y - 0.05f, selection_object.transform.position.z); new_go.transform.parent = areaBuildingContainer; new_go.GetComponent <Renderer>().material = areaBuildingMaterial; //don't forget to set layer new_go.layer = InterfaceController.LAYER_AREA_BUILDING; // add components, and add collider AreaBuilding new_area = new_go.AddComponent <AreaBuilding> (); new_go.AddComponent <BoxCollider> (); new_go.GetComponent <BoxCollider> ().size = new Vector3(0.99f, 0.99f, 0.99f); // otherwise it's counts as outside and size ends up at +1 because of Setup new_area.Setup(type, buildingFactory); // reflect changes in grid GridHelper.BuildGridObject(new_area); // and finally add to airport list airport.AddAreaBuilding(new_area); // reset position selection_object.transform.position = oldPosition; return(new_area); }