我现在用的是Unity5。尝试 setDestination 时出现此错误。
“SetDestination”只能在已放置在导航网格上的活动代理上调用。
UnityEngine.NavMeshAgent:SetDestination(Vector3)
CompleteProject.EnemyMovement:Update() (位于 Assets/_CompletedAssets/Scripts/Enemy/EnemyMovement.cs:30)
My code.
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位于地面之上。
2.进入Window->Navigation->Bake并点击bake。蓝色区域是第三人称可以到达地面的地方。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)