1. 程式人生 > >用 MoveTowards實現多點移動

用 MoveTowards實現多點移動

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveCube : MonoBehaviour {
    public Vector3[] pos;
    int num=0;
    // Use this for initialization
    // Update is called once per frame
    void Update () {
     transform.position= Vector3.MoveTowards(transform.position,pos[num],0.1f
); transform.LookAt(pos[num]); if (transform.position==pos[num]) { num++; if (num >pos.Length-1) { num = pos.Length - 1; } } } }