Spawning objects around a point

Hello! I am somewhat new to scripting in Unity and have no idea of ways to do this. I want to spawn a cube made of smaller cubes around 0,0,0. However, the size of the big cube spawned will differ based on the number of little cubes used building it, but still needed to remain centered at 0,0,0. Is their any way to move a group of objects to center them at 0,0,0 or is their another way to do this. Thanks.

Hi!

First create that “cube made of smaller cubes” and put it into a prefab.

Next, copy the code below (this is a code I found on unity answers too and just modified it, credits to the owner of the code and I forgot who he/she is) and paste it into a new JS script.

Then, create an empty game object and drag the JS script in it.

Select the prefab that you’ve created and add a rigidbody on it.

Once the prefab has a rigidbody, click the empty game object with the script, apply the prefab that you’ve created to that script.

Make sure that the “cube made of smaller cubes” you’ve made is positioned at (0,0,0)

var timer : float = 0.0;
var spawning : boolean = false;
var prefab : Rigidbody;
var spawn1 : Transform;

  
function Update () {
 //check if spawning at the moment, if not add to timer
 Debug.Log(Application.loadedLevelName);
 if(!spawning){
  timer += Time.deltaTime;
 }
 //when timer reaches 2 seconds, call Spawn function
 if(timer >= 2){
  Spawn();
 }
}
 
function Spawn(){
 //set spawning to true, to stop timer counting in the Update function
 spawning = true;
 //reset the timer to 0 so process can start over
 timer = 0;
 
 //select a random number, inside a maths function absolute command to ensure it is a whole number
 var randomPick : int = Mathf.Abs(Random.Range(1,3));
 
 //create a location 'Transform' type variable to store one of 3 possible locations declared at top of script
 var location : Transform;
 var thingToMake : Rigidbody;
 //check what randomPick is, and select one of the 3 locations, based on that number
 if(randomPick == 1){
  location = spawn1;
 
  Debug.Log("Chose pos 1");
 thingToMake = Instantiate(prefab, location.position, location.rotation);
  
 
 }
 
 
 //halt script for 1 second before returning to the start of the process
 yield WaitForSeconds(1);
 //set spawning back to false so timer may start again
 spawning = false;
}