私はゲーム上で団結5で働いていますし、私は現在、このエラーを取得しています:SetDestinationおよび活性剤/ NavMesh問題
「SetDestinationは、」のみに配置された活性剤で呼び出すことができますNavMesh。 (資産/スクリプト/敵/ EnemyMovement.csで:25)アップデート(): UnityEngine.NavMeshAgent:SetDestination(のVector3) EnemyMovementは
enemyMovementスクリプトの私のコードは次のとおりです。
using UnityEngine;
using System.Collections;
public class EnemyMovement : MonoBehaviour
{
Transform player;
PlayerHealth playerHealth;
EnemyHealth enemyHealth;
NavMeshAgent nav;
void Awake()
{
player = GameObject.FindGameObjectWithTag ("Player").transform;
playerHealth = player.GetComponent <PlayerHealth>();
enemyHealth = GetComponent <EnemyHealth>();
nav = GetComponent <NavMeshAgent>();
}
void Update()
{
if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)
{
nav.SetDestination (player.position);
}
else
{
nav.enabled = false;
}
}
}
今私は、ほとんど同じ質問がここにあることを知ってください:Unity - "SetDestination" can only be called on an active agent that has been placed on a NavMesh. UnityEngine.NavMeshAgent:SetDestination(Vector3)しかし、質問はしっかりとした応答を持っていないようで、私はいくつかの回答をしてみましたが、何も動作しないようです。私のゲームはうまくいくと言うでしょう。しかし、私は、プレイヤーが 'B'を押すと、すべての敵が画面上で死ぬという能力を追加しました。私が「B」を押すと、敵は死ぬが、システムは「クラッシュ」し、そのエラーメッセージが出る。
EnemyManager.cs:
public void Kill(int InstanceID)
{
if (EnemyManager.Instance.EnemyList.ContainsKey(InstanceID))
EnemyManager.Instance.EnemyList.Remove(InstanceID);
}
public void DeathToAll()
{
Dictionary<int, Object> TempEnemyList = new Dictionary<int, Object>(EnemyManager.Instance.EnemyList);
foreach (KeyValuePair<int, Object> kvp in TempEnemyList)
{
// kvp.Key; // = InstanceID
// kvp.Value; // = GameObject
GameObject go = (GameObject)kvp.Value;
go.GetComponent<EnemyHealth>().Death();
}
}
Enemyhealth.cs
public void Death()
{
// The enemy is dead.
isDead = true;
// Turn the collider into a trigger so shots can pass through it.
capsuleCollider.isTrigger = true;
// Tell the animator that the enemy is dead.
anim.SetTrigger ("Dead");
// Change the audio clip of the audio source to the death clip and play it (this will stop the hurt clip playing).
enemyAudio.clip = deathClip;
enemyAudio.Play();
// Kill the Enemy (remove from EnemyList)
// Get the game object associated with "this" EneymHealth script
// Then get the InstanceID of that game object.
// That is the game object that needs to be killed.
EnemyManager.Instance.Kill(this.gameObject.GetInstanceID());
}
私の推測では、すべての敵が死んでいるにもかかわらず、それは条件「敵ヘルス。現在のヘルス> 0 && playerHealth.currentHealth> 0」がまだ であると思われます。私はあなたの能力を使用するときに健康状態が0に設定されていると推測します - 他のスクリプトで 'enemyHealth.currentHealth'をリセットしていますか? 'Update()'にその値を記録し、予期せず変更があるかどうかを確認してください。 – Serlite
私はすぐにそれを試みるでしょう!私は何が起こったのかを説明するために戻ってくるでしょう!ありがとうございます –
ええ、私は:Debug.Log( "敵の健康:" + enemyHealth.currentHealth);私は100をコンソール上に表示するか、現在の敵の健康状態を確認します。決して落ちない。 –