Search Unity

3D Graph making

Discussion in 'Scripting' started by fairuzsobri96, Apr 29, 2018.

  1. fairuzsobri96

    fairuzsobri96

    Joined:
    Sep 28, 2017
    Posts:
    2
    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?
     

    Attached Files:

  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    fairuzsobri96 likes this.
  3. fairuzsobri96

    fairuzsobri96

    Joined:
    Sep 28, 2017
    Posts:
    2
    Thank you so much ! Now finally understand