創作內容

1 GP

AI-巡邏(指定地點)---NavMeshAgent

作者:麋瑀│2017-04-25 16:04:27│巴幣:2│人氣:914
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class NewBehaviourScriptSOS : MonoBehaviour {
    public Transform[] points;
    private int destPoint = 0;
    private NavMeshAgent agent;
    
    static Animator anim;//動畫面板
    
    void Start()
    {
        anim = GetComponent<Animator>();

        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).
        //禁用自動制動允許持續運動在點之間(即,代理不會減慢接近目的地點)。
      //  agent.autoBraking = false;  //當啟用時,代理將在到達目的地時減慢速度。

        GotoNextPoint();
    }


    void GotoNextPoint()
    {
        anim.SetBool("Idle", false);
        // Returns if no points have been set up
        //如果沒有設置點,則返回
        if (points.Length == 0)
            return;
        {
            anim.SetBool("Walk", true);
        }

        // Set the agent to go to the currently selected destination.
        agent.destination = points[destPoint].position;
        //nav.SetDestination(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.remainingDistance < 0.5f)
            GotoNextPoint();
    }
}

引用網址:https://home.gamer.com.tw/TrackBack.php?sn=3555538
All rights reserved. 版權所有,保留一切權利

相關創作

留言共 0 篇留言

我要留言提醒:您尚未登入,請先登入再留言

1喜歡★k940714675 可決定是否刪除您的留言,請勿發表違反站規文字。

前一篇:使AI在指定地點巡邏... 後一篇:AI(觀察附近+看到敵人...

追蹤私訊切換新版閱覽

作品資料夾

huaing123雙標偷襲成癮霸凌仔
疲勞的一天,再加上你從井口丟下的一塊大石......真棒🙂🙃🙂🙃看更多我要大聲說昨天23:05


face基於日前微軟官方表示 Internet Explorer 不再支援新的網路標準,可能無法使用新的應用程式來呈現網站內容,在瀏覽器支援度及網站安全性的雙重考量下,為了讓巴友們有更好的使用體驗,巴哈姆特即將於 2019年9月2日 停止支援 Internet Explorer 瀏覽器的頁面呈現和功能。
屆時建議您使用下述瀏覽器來瀏覽巴哈姆特:
。Google Chrome(推薦)
。Mozilla Firefox
。Microsoft Edge(Windows10以上的作業系統版本才可使用)

face我們了解您不想看到廣告的心情⋯ 若您願意支持巴哈姆特永續經營,請將 gamer.com.tw 加入廣告阻擋工具的白名單中,謝謝 !【教學】