Hello, I’m trying to spawn objects one after the other with random height.

The problem is that for that I need to get half the height of the previous object and half the height of the new object and calculate it as the new position.y of the new object.

I tried a lot of ideas, and search the forums & the web for a solution. i’m about to lose it

This is my current code, anyone have an idea?

```
public GameObject cube;
Vector3 cubeHeight = new Vector3(0,0,0);
void Start()
{
//SpawnTheCube();
InvokeRepeating("SpawnTheCube", 0.5f, 0.5f);
}
void SpawnTheCube()
{
GameObject newCube = (GameObject)Instantiate(cube, new Vector3(0, cubeHeight.y, 0), Quaternion.identity, transform);
newCube.transform.localScale = new Vector3(newCube.transform.localScale.x, UnityEngine.Random.Range(1, 6), newCube.transform.localScale.z); //Randomize the height
float newCubeHeight = newCube.transform.localScale.y / 2; //Half the height of the new spawned cube
cubeHeight.y += newCubeHeight;
}
```