Hello im trying to work on this 3D bar graph. Using cube prefab and the value increasing with 1,2,3…
public GameObject objectPrefab;
public Vector2 location;
void Awake(){
for (int i = 0; i < 5; i++) {
float x = i;
float y = i;
location.x = x; // the position should be (1,0),(2,0)
location.y = 0;
GameObject newcube = Instantiate(objectPrefab, location, Quaternion.identity) as GameObject; // instatiate the object
newcube.transform.localScale = new Vector3(1.0f,y,1.0f); // change its local scale in y as the height of cube
}
}
}
But turns out the bar graph doesn’t align together. How to make it on a straight line?
In this case the cubes’ center will always be at y=0, and after applying the scaling, they will be scaled equally towards the negative and positive y values. To fix this, you should set the coordinate, so that ycoord = (scale / 2)