【原】unity3d空间画线

    public GameObject line;
    public Transform[] wayPoint;
    int i;
    void Start()
    {
        i=0;
    }
    void Update()
    {
        if(i<wayPoint.Length-1)
        {
            Vector3 tempPos=(wayPoint[i].position+wayPoint[i+1].position)/2;//计算两个点的中点坐标,
            GameObject go=(GameObject)Instantiate(line,tempPos,Quaternion.identity) ;//在两个点的中点处实例化线条,因为对物体的缩放,是从中心向两边延伸
            go.name=""+i;
            go.transform.right=(go.transform.position-wayPoint[i].position).normalized;//改变线条的朝向
            float distance=Vector3.Distance(wayPoint[i].position,wayPoint[i+1].position);//计算两点的距离
            go.transform.localScale=new Vector3(distance,0.01f,0.01f);//延长线条,连接两点。
            i++;
        }
    }

posted @ 2012-07-11 22:28  U_探索  阅读(5795)  评论(0编辑  收藏  举报