Place GameObjects with even horizontal distribution

I’m looking to place an arbitrary number of GameObjects evenly across an arbitrary width. I’ve got something close but it isn’t quite right.

```

  •        float newSpacing = rowWidth / (numberOfBlocks + 1);
    
          for (int i = 0; i < numberOfBlocks; i++)
          {
                  GameObject newBlock = (GameObject)Instantiate(blockTemplate, this.gameObject.transform.position, Quaternion.identity);
                  newBlock.transform.parent = this.gameObject.transform;
    
                  float newXPosition = (rowWidth / 2) - (newSpacing * i) - this.gameObject.transform.localScale.x;
                  newBlock.transform.localPosition = new Vector3(newXPosition, 0, 0);
          }*
    

```
What I am attempting there is to first calculate the spacing based on the number of objects I want and the overall width, then place the objects accordingly. I’m finding that while they are spaced evenly, but they’re not centered inside the expected width. What am I missing?

I think the issue is that the center point of blockTemplate. you need to know the width of this object. and add half it’s width to the x position.

attach a screen shot so we can see what it’s doing wrong

In addition to the previous poster’s feedback, an observation I made is that you are subtracting localScale.x and I don’t think that that applicable here. Since localScale is a proportional value…In closing, I believe your scenario wouldn’t need to factor the scaling at all, at first glance.