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();
}
}