public class QiuZhuan : MonoBehaviour {
public Transform[] points;//定义三个球
Transform nextQiu;//定义要移动到球的位置
int nowindex;//当前的索引
int speed;
// Use this for initialization
void Start () {
nextQiu=points[0];
nowindex=0;
speed=10;
}
// Update is called once per frame
void Update () {
if(Vector3.Distance(nextQiu.position,transform.position)>0.1f)//判断当前物体到接下来物体距离
{
transform.Translate((nextQiu.position-transform.position).normalized*speed*Time.deltaTime,Space.World);//朝下个物体移动(nextQiu.position-transform.position)代表方向向量
}
else//接下来要移动的
{
nowindex =(nowindex+1)%(points.Length);
nextQiu=points[nowindex];
}
}
public Transform[] points;//定义三个球
Transform nextQiu;//定义要移动到球的位置
int nowindex;//当前的索引
int speed;
// Use this for initialization
void Start () {
nextQiu=points[0];
nowindex=0;
speed=10;
}
// Update is called once per frame
void Update () {
if(Vector3.Distance(nextQiu.position,transform.position)>0.1f)//判断当前物体到接下来物体距离
{
transform.Translate((nextQiu.position-transform.position).normalized*speed*Time.deltaTime,Space.World);//朝下个物体移动(nextQiu.position-transform.position)代表方向向量
}
else//接下来要移动的
{
nowindex =(nowindex+1)%(points.Length);
nextQiu=points[nowindex];
}
}
}