亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Unity如何使游戲對象無休止地通過航路點?

Unity如何使游戲對象無休止地通過航路點?

C#
千萬里不及你 2021-04-29 18:11:13
我有以下代碼:using UnityEngine;using UnityEngine.AI;using System.Collections;public class AutoPilot : MonoBehaviour {public Transform[] points;private int destPoint = 0;private NavMeshAgent agent;void Start () {    agent = GetComponent<NavMeshAgent>();    // Disabling auto-braking allows for continuous movement    // between points (ie, the agent doesn't slow down as it    // approaches a destination point).    GotoNextPoint();}void GotoNextPoint() {    // Returns if no points have been set up    if (points.Length == 0)        return;    // Set the agent to go to the currently selected destination.    agent.destination = points[destPoint].transform.position;    // Choose the next point in the array as the destination,    // cycling to the start if necessary.    destPoint = (destPoint + 1) % points.Length;}void Update () {    // Choose the next destination point when the agent gets    // close to the current one.    if (!agent.pathPending && agent.remainingDistance < 2f)        GotoNextPoint();}}我經過航路點的地方,代理跟蹤它們,但是當我到達最后一個航路點時,如何使它重新啟動?繼續前進?可以通過某種方式重置還是最好的方法是什么?
查看完整描述

1 回答

?
忽然笑

TA貢獻1806條經驗 獲得超5個贊

我通過添加以下內容修復了該問題:


if (destPoint == points.Length) {

        destPoint = 0;

    }


查看完整回答
反對 回復 2021-05-08
  • 1 回答
  • 0 關注
  • 147 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號