- Home /
Question by
Serellyn · Jul 10, 2021 at 06:46 PM ·
scalesizeinstantiate prefab
Stack prefab cube neatly on top of eachother
I'm having troubles stacking prefabs, which are basically flat cubes, neatly on top of eachother. Any help would be appreciated, I can't figure out what I'm doing wrong.
Currently the output of my code looks like this:
What I want to achieve, is this (excuse the cursor, it's not his fault):
My code is as follows:
private void QuickAndDirty()
{
float towerHeight = 0.1f;
for (var i=0; i < 10; i++)
{
float randomScale = Random.Range(0.1f, 0.5f);
block.transform.localScale = new Vector3(5,randomScale,5);
Vector3 location = new Vector3(0,towerHeight,0);
Instantiate(block, location, Quaternion.identity);
float h = block.GetComponent<Renderer>().bounds.size.y;
towerHeight += h;
}
}
incorrect.png
(16.3 kB)
correct.png
(18.2 kB)
Comment
Your answer
Follow this Question
Related Questions
Newbiew question: how to size objects? 1 Answer
When my character is changed to a Humanoid, it gets huge 1 Answer
Why do some 3D assets placed in different projects have different sizes with the same scale on each? 0 Answers
Positioning gameobjects by a corner, not by center 0 Answers
Scale like in Hammer Editor? 0 Answers