简体   繁体   English

Unity navMeshAgent 无法在地形上工作

[英]Unity navMeshAgent not working on terrain

The Unity Navmeshagent is not working !on terrain! Unity Navmeshagent在地形上不起作用! . . I'm very kinda new to unity and need help with the navmesh agent.我对统一非常陌生,需要 navmesh 代理的帮助。

It's baking fine just that the entity or slender man is not moving.只是实体或纤细的人没有移动,这很好。 It's actually in the inspector but it's only like 0.0001 per second.它实际上在检查器中,但每秒只有 0.0001。 Bake and navmesh agent settings are the photos. Bake 和 navmesh 代理设置是照片。

Script:脚本:

using UnityEngine;
using UnityEngine.AI;

public class enemymovement : MonoBehaviour
{
    private NavMeshAgent nma;
    public Transform player;
    private void Awake()
    {
        nma = GetComponent<NavMeshAgent>();
        StartCoroutine("followpath");
    }

    private IEnumerator followpath()
    {
        while (true)
        {
            nma.SetDestination(player.position);
            yield return new WaitForSeconds(0.1f);
        }
    }
}

You need to use nma.SetDestination(player.position)您需要使用nma.SetDestination(player.position)

And don't put this in an update because it means that your agent will try to calculate a new path in every frame.并且不要将其放入更新中,因为这意味着您的代理将尝试在每一帧中计算新路径。 I suggest using a Coroutine that will call SetDestination from time to time instead of every update.我建议使用不时调用 SetDestination 而不是每次更新的协程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM