如何使用线条渲染器绘制折线图/图表?

时间:2014-05-06 06:55:06

标签: unity3d linechart linegraph

我被告知要创建折线图/图表,我首先需要知道如何在游戏场景中创建像线条一样的图形。我做了,现在我应该如何绘制并将其制作成折线图?我需要绘制一个实时图表。 这是使用Line渲染器绘制线条的代码。

public Transform origin;
    public Transform destination;


    public float lineDrawSpeed = 6f;

    // Use this for initialization
    void Start () 
    {
        lineRenderer = GetComponent<LineRenderer> ();
        lineRenderer.SetPosition(0, origin.position);

        lineRenderer.SetWidth(.10f, .10f);

        dist = Vector3.Distance (origin.position, destination.position);

    }

    // Update is called once per frame
    void Update () 
    {
        if (counter < dist) {

        counter += .1f / lineDrawSpeed;

        float x = Mathf.Lerp (0, dist, counter);

        Vector3 pointA = origin.position;
        Vector3 pointB = destination.position;

        //Get the unit vector in the desired direction, multiply by the desired length and add the starting point.
        Vector3 pointAlongLine = x * Vector3.Normalize (pointB - pointA) + pointA;

        lineRenderer.SetPosition (1, pointAlongLine);

}
}
}

0 个答案:

没有答案