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++;
}
}