Moh*_*din 4 c# unity-game-engine
我现在正在使用Unity5。尝试 setDestination 时出现此错误。
\n\n\n\n\n“SetDestination”只能在已放置在 NavMesh 上的活动代理上调用。\n UnityEngine.NavMeshAgent:SetDestination(Vector3)\n CompleteProject.EnemyMovement:Update()(位于 Assets/_CompletedAssets/Scripts/Enemy/EnemyMovement。 CS:30)
\n
我的代码。
\n\nusing 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}\nRun Code Online (Sandbox Code Playgroud)\n\n参考: https: //github.com/datomnurdin/SurvivalShooter
\n| 归档时间: |
|
| 查看次数: |
34156 次 |
| 最近记录: |