Le script peut être attaché au lecteur.
Il est nécessaire d'ajouter le composant d'animation Animator au lecteur
et de mettre l'animation qui doit être jouée dans le composant d'animation.
Placez les composants d'animation dans des variables d'animation publiques.
NavMeshAgent agent; // 导航组件
public Animator anim; // 获取动画
float motionSmoothTime = 0.1f;
// Start is called before the first frame update
void Start()
{
agent = GetComponent<NavMeshAgent>();
// 获取导航组件
}
void Update()
{
// 路程除以时间等于速度
float speed = agent.velocity.magnitude / agent.speed;
// 设置动画Speed浮点数的值以及跟新的频率随着时间增加
anim.SetFloat("Speed",speed,motionSmoothTime,Time.deltaTime);
}