Unity - “SetDestination”只能在已放置在导航网格上的活动代理上调用。UnityEngine.NavMeshAgent:SetDestination(Vector3)

Moh*_*din 4 c# unity-game-engine

我现在正在使用Unity5。尝试 setDestination 时出现此错误。

\n\n
\n

“SetDestination”只能在已放置在 NavMesh 上的活动代理上调用。\n UnityEngine.NavMeshAgent:SetDestination(Vector3)\n CompleteProject.EnemyMovement:Update()(位于 Assets/_CompletedAssets/Scripts/Enemy/EnemyMovement。 CS:30)

\n
\n\n

我的代码。

\n\n
using UnityEngine;\nusing System.Collections;\n\nnamespace CompleteProject\n{\n    public class EnemyMovement : MonoBehaviour\n    {\n        Transform player;               // Reference to the player\'s position.\n        PlayerHealth playerHealth;      // Reference to the player\'s health.\n        EnemyHealth enemyHealth;        // Reference to this enemy\'s health.\n        NavMeshAgent nav;               // Reference to the nav mesh agent.\n\n\n        void Awake ()\n        \xc3\xa5{\n            // Set up the references.\n            player = GameObject.FindGameObjectWithTag ("Player").transform;\n            playerHealth = player.GetComponent <PlayerHealth> ();\n            enemyHealth = GetComponent <EnemyHealth> ();\n            nav = GetComponent <NavMeshAgent> ();\n        }\n\n\n        void Update ()\n        {\n            // If the enemy and the player have health left...\n            if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)\n            {\n                // ... set the destination of the nav mesh agent to the player.\n                nav.SetDestination (player.position);\n            }\n            // Otherwise...\n            else\n            {\n                // ... disable the nav mesh agent.\n                nav.enabled = false;\n            }\n        }\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

参考: https: //github.com/datomnurdin/SurvivalShooter

\n

小智 5

1.确保您的thirdPersonController位于地面之上。

2.进入Window->Navigation->Bake并点击bake。蓝色区域是第三人称可以到达地面的地方。