wp[]が経路の配列 wpStateが現在向かっている経路配列の遷移位置 初期設定として、経路をwp配列に設定する。 経路自体はsceneにおいておけば、視覚的に位置を設定できる 自機の初期位置をwp[0]に設定し、wpState=1として、次の目標を1にする void Start() { wpMaxState=5; wp = new Vector3[wpMaxState+1]; for(int i=0;i<=wpMaxState;i++) { GameObject.Find("Waypoint00"+i.ToString()).GetComponent<Renderer>().enabled = false; wp[i] = GameObject.Find("Waypoint00"+i.ToString()).transform.position; } transform.position = wp[0]; wpState=1; } 目標の経路位置と近くなったら、経路目標をwpState++で進める 経路目標が最後まで来たら、ゴール到着後の処理を行う まだ目標経路まで距離がある場合は、スムーズにそちらへ回転し、進む void Update () { if( Vector3.Distance( transform.position,wp[wpState] )<=0.1f ) { wpState++; if(wpState>wpMaxState) { /* goal */ } } else { transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(wp[wpState] - transform.position), 1f); transform.position += transform.forward * speed; } }