本文介绍了Unity-"SetDestination"只能在已放置在NavMesh上的活动代理上调用. UnityEngine.NavMeshAgent:SetDestination(Vector3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在正在使用Unity5.尝试setDestination时出现此错误.
I'm using Unity5 right now. I got this error when try to setDestination.
我的代码.
using UnityEngine;
using System.Collections;
namespace CompleteProject
{
public class EnemyMovement : MonoBehaviour
{
Transform player; // Reference to the player's position.
PlayerHealth playerHealth; // Reference to the player's health.
EnemyHealth enemyHealth; // Reference to this enemy's health.
NavMeshAgent nav; // Reference to the nav mesh agent.
void Awake ()
å{
// Set up the references.
player = GameObject.FindGameObjectWithTag ("Player").transform;
playerHealth = player.GetComponent <PlayerHealth> ();
enemyHealth = GetComponent <EnemyHealth> ();
nav = GetComponent <NavMeshAgent> ();
}
void Update ()
{
// If the enemy and the player have health left...
if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)
{
// ... set the destination of the nav mesh agent to the player.
nav.SetDestination (player.position);
}
// Otherwise...
else
{
// ... disable the nav mesh agent.
nav.enabled = false;
}
}
}
}
参考: https://github.com/datomnurdin/SurvivalShooter
推荐答案
1.确保您的thirdPersonController在地面上.
1.Make sure that your thirdPersonController is above the ground.
2.转到窗口"->导航"->烘焙",然后单击烘焙".蓝色区域是第三人称可以到达地面的地方.
2.Go to Window->Navigation->Bake and click bake.The blue area is where the thirdperson can reach in the ground.
这篇关于Unity-"SetDestination"只能在已放置在NavMesh上的活动代理上调用. UnityEngine.NavMeshAgent:SetDestination(Vector3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!